How to correct the error "implicit declaration of function '

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
leetow2003
Member
Member
Posts: 70
Joined: Fri Nov 19, 2010 6:54 pm

How to correct the error "implicit declaration of function '

Post by leetow2003 »

Look:

Code: Select all

//the file:Makefile
ifneq ($(KERNELRELEASE),)
obj-m += __module_address.o
else
PWD := $(shell pwd)
KVER := $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
all:
	$(MAKE) -C $(KDIR) M=$(PWD)
clean:
	rm -rf *.o *.mod.c *.ko *.symvers *.order *.markers *~
endif

//the file __module_address.c
#include <linux/module.h>
#include <linux/init.h>
MODULE_LICENSE("GPL"); 
static int __init __module_address_init(void); 
static void __exit __module_address_exit(void);

int a_module(void)
{
	return 0;
}
int __init __module_address_init(void) 
{ 
	struct module * ret ; 
	unsigned long addr = (unsigned long)a_module; 

	preempt_disable();   
	ret = __module_address(addr) ;
	preempt_enable();   

	if( ret != NULL )
	{
		printk("<0>ret->name: %s\n",ret->name);   
		printk("<0>ret->state: %d\n",ret->state);   
       	        printk("<0>ret->core_size: %lu\n",ret->core_size);  
                printk("<0>refs of %s is %d\n",ret->name, module_refcount(ret)); 
	}	
	else
	{
		printk("<0>__module_address return NULL !\n");
	}	

	return 0; 
}

void __exit __module_address_exit(void) 
{ 
	printk("<0>module exit ok!\n"); 
}

module_init(__module_address_init); 
module_exit(__module_address_exit); 
When I compile the file __module_address.c,it always display
the error: "implicit declaration of function '__module_address'",
how to correct it?
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to correct the error "implicit declaration of functi

Post by iansjack »

Compiles fine on my system (Gentoo with 3.11.1 kernel and using gcc-4.7.3) with a couple of warnings. But it could be because you are calling __module_address with an unsigned long argument when it is declared with a void argument.
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: How to correct the error "implicit declaration of functi

Post by sortie »

This is not a generic Linux help forum. You should direct your Linux internals questions at some place like LKML or other Linux communities.

This warning occurs whenever you attempt to use a function that hasn't had a prototype. You need to forward declare it (by possibly including the appropriate headers).
Post Reply