LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Could not compile sample driver module in Suse 10.3 (https://www.linuxquestions.org/questions/linux-kernel-70/could-not-compile-sample-driver-module-in-suse-10-3-a-648760/)

pranav_patil 06-12-2008 04:58 AM

Could not compile sample driver module in Suse 10.3
 
I was trying to compile a module to create a sample driver.
Initially I tried to compile a dummy module and load in the system
using the command,

gcc -D_KERNEL_ -I/usr/src/linux/include -DMODULE -Wall -O2 -c hello.c

The code for hello.c is as follows:

#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */

static int __init hello_start(void)
{
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;
}

static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye Mr.\n");
}

module_init(hello_start);
module_exit(hello_end);

I get the errors as follows:

error : asm/bitops.h : No such file or directory.
error : asm/thread_info.h : No such file or directory.
error : thread_info.h : In function 'set_ti_thread_flag'.
error : asm/linkage.h : No such file or directory.
error : asm/bug.h : No such file or directory.
error : asm/system.h : No such file or directory.
error : asm/atomic.h : No such file or directory.
error : asm/module.h : No such file or directory.
error : asm/processor.h : No such file or directory.
error : asm/cache.h : No such file or directory.
error : asm/current.h : No such file or directory.
error : asm/local.h : No such file or directory.

The above was the brief summary of errors what I was getting.
Can you help me with the problem and find a suitable solution ?

komodo 06-14-2008 01:36 AM

My guess is that you did not install the kernel header files before compiling this.

pranav_patil 06-14-2008 07:36 AM

I installed the entire kernel package from suse installation disc. But there is no folder
such as /usr/src/linux/include/linux/asm . There are folders like /usr/src/linux/include/linux/asmi386 and others.

komodo 06-14-2008 08:40 AM

ok, so, the headers are found in a different directory than gcc thinks. In that case, you may have to change the prefix.
you have tried
Code:

gcc -D_KERNEL_ -I/usr/src/linux/include -DMODULE -Wall -O2 -c hello.c
this basically tells gcc to look for the include files in the path /usr/src/linux/include/... However, as you have found, on your system the correct path should be /usr/src/linux/include/linux/.... So, maybe you should try this:

Code:

gcc -D_KERNEL_ -I/usr/src/linux/include/linux -DMODULE -Wall -O2 -c hello.c
If that doesn't work, we'll continue the search...(you may then have to set a symlink to an alternative directory name and point gcc to that)...on the other hand, perhaps other have a quick solution...

pranav_patil 06-20-2008 08:56 AM

Now I changed My code to as follows :

hello.c ..............

#include <module.h>

#if defined(CONFIG_SMP)
#define __SMP__
#endif

#if defined(CONFIG_MODVERSIONS)
#define MODVERSIONS
#include <modversions.h>
#endif

#include <kernel.h>

int init_module(void)
{
printk("<7>Hello, kernel!!\n");
return 0;
}

void cleanup_module(void)
{
printk("<7>Good-bye, kernel!!\n");
}
--------------------------------------------------------------------------
Executed the command you told :
gcc -D _KERNEL_ -I/usr/src/linux/include/linux -DMODULE -Wall -O2 -c hello.c

I got the following errors:

In file included from hello.c:2:
/usr/src/linux/include/linux/module.h:9:28: error: linux/spinlock.h: No such file or directory
/usr/src/linux/include/linux/module.h:10:24: error: linux/list.h: No such file or directory
/usr/src/linux/include/linux/module.h:12:28: error: linux/compiler.h: No such file or directory
/usr/src/linux/include/linux/module.h:13:25: error: linux/cache.h: No such file or directory
/usr/src/linux/include/linux/module.h:14:24: error: linux/kmod.h: No such file or directory
/usr/src/linux/include/linux/module.h:16:29: error: linux/stringify.h: No such file or directory
/usr/src/linux/include/linux/module.h:17:27: error: linux/kobject.h: No such file or directory
/usr/src/linux/include/linux/module.h:18:31: error: linux/moduleparam.h: No such file or directory
/usr/src/linux/include/linux/module.h:19:23: error: asm/local.h: No such file or directory
/usr/src/linux/include/linux/module.h:21:24: error: asm/module.h: No such file or directory
In file included from hello.c:2:
/usr/src/linux/include/linux/module.h:48: error: field ‘attr’ has incomplete type
/usr/src/linux/include/linux/module.h:59: error: field ‘kobj’ has incomplete type
/usr/src/linux/include/linux/module.h: In function ‘lookup_module_symbol_name’:
/usr/src/linux/include/linux/module.h:535: error: ‘ERANGE’ undeclared (first use in this function)
/usr/src/linux/include/linux/module.h:535: error: (Each undeclared identifier is reported only once
/usr/src/linux/include/linux/module.h:535: error: for each function it appears in.)
/usr/src/linux/include/linux/module.h: In function ‘lookup_module_symbol_attrs’:
/usr/src/linux/include/linux/module.h:540: error: ‘ERANGE’ undeclared (first use in this function)
/usr/src/linux/include/linux/module.h: In function ‘module_get_kallsym’:
/usr/src/linux/include/linux/module.h:547: error: ‘ERANGE’ undeclared (first use in this function)
/usr/src/linux/include/linux/module.h: At top level:
/usr/src/linux/include/linux/module.h:596: warning: ‘struct kernel_param’ declared inside parameter list
/usr/src/linux/include/linux/module.h:596: warning: its scope is only this definition or declaration, which is probably not what you want
hello.c: In function ‘init_module’:
hello.c:17: warning: implicit declaration of function ‘printk’

The text is corrupted because of the transferring of data from linux to windows.
Can you help me with the problem please ?


All times are GMT -5. The time now is 06:09 AM.