Page 1 of 1

How to correct the error "implicit declaration of function '

Posted: Fri Sep 27, 2013 12:32 am
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?

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

Posted: Fri Sep 27, 2013 4:03 am
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.

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

Posted: Fri Sep 27, 2013 4:14 am
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).