LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-27-2006, 08:56 AM   #1
antdengineer
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Rep: Reputation: 0
Unhappy Trying to Compile "hello world" Kernel Module (please help!)


Hello,

I am trying to compile an example from the Oreilly Press book "Linux Device Drivers". Here is the example code:

Code:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>	

MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
    printk(KERN_ALERT "Hello, world\n");
    return 0;
}

static void hello_exit(void)
{
    printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);
The problem is that when i try to compile with this: gcc -c -I /usr/src/linux-2.6.16/include/ hello.c , I get all of this:

Code:
In file included from /usr/src/linux-2.6.16/include/linux/sched.h:12,
                 from /usr/src/linux-2.6.16/include/linux/module.h:10,
                 from hello.c:2:
/usr/src/linux-2.6.16/include/linux/jiffies.h:75: error: syntax error before ‘jiffies_64’
/usr/src/linux-2.6.16/include/linux/jiffies.h:79: error: syntax error before ‘get_jiffies_64’
/usr/src/linux-2.6.16/include/linux/jiffies.h:79: warning: data definition has no type or storage class
In file included from /usr/src/linux-2.6.16/include/linux/sched.h:12,
                 from /usr/src/linux-2.6.16/include/linux/module.h:10,
                 from hello.c:2:
/usr/src/linux-2.6.16/include/linux/jiffies.h:250:47: error: division by zero in #if
/usr/src/linux-2.6.16/include/linux/jiffies.h: In function ‘jiffies_to_msecs’:
/usr/src/linux-2.6.16/include/linux/jiffies.h:253: error: ‘MSEC_PER_SEC’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:253: error: (Each undeclared identifier is reported only once
/usr/src/linux-2.6.16/include/linux/jiffies.h:253: error: for each function it appears in.)
/usr/src/linux-2.6.16/include/linux/jiffies.h:261:47: error: division by zero in #if
/usr/src/linux-2.6.16/include/linux/jiffies.h: In function ‘jiffies_to_usecs’:
/usr/src/linux-2.6.16/include/linux/jiffies.h:264: error: ‘USEC_PER_SEC’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:274:47: error: division by zero in #if
/usr/src/linux-2.6.16/include/linux/jiffies.h: In function ‘msecs_to_jiffies’:
/usr/src/linux-2.6.16/include/linux/jiffies.h:277: error: ‘MSEC_PER_SEC’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:287:47: error: division by zero in #if
/usr/src/linux-2.6.16/include/linux/jiffies.h: In function ‘usecs_to_jiffies’:
/usr/src/linux-2.6.16/include/linux/jiffies.h:290: error: ‘USEC_PER_SEC’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h: In function ‘timespec_to_jiffies’:
/usr/src/linux-2.6.16/include/linux/jiffies.h:311: error: called object ‘u64’ is not a function
/usr/src/linux-2.6.16/include/linux/jiffies.h:311: error: called object ‘u64’ is not a function
/usr/src/linux-2.6.16/include/linux/jiffies.h:311: error: ‘NSEC_PER_SEC’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:312: error: called object ‘u64’ is not a function
/usr/src/linux-2.6.16/include/linux/jiffies.h:312: error: called object ‘u64’ is not a function
/usr/src/linux-2.6.16/include/linux/jiffies.h:315: error: syntax error before ‘sec’
/usr/src/linux-2.6.16/include/linux/jiffies.h:315: error: syntax error before ‘NSEC_PER_SEC’
/usr/src/linux-2.6.16/include/linux/jiffies.h:315: error: called object ‘u64’ is not a function
/usr/src/linux-2.6.16/include/linux/jiffies.h:315: error: syntax error before ‘)’ token
/usr/src/linux-2.6.16/include/linux/jiffies.h: In function ‘jiffies_to_timespec’:
/usr/src/linux-2.6.16/include/linux/jiffies.h:328: error: syntax error before ‘nsec’
/usr/src/linux-2.6.16/include/linux/jiffies.h:329: error: ‘nsec’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:329: error: ‘NSEC_PER_SEC’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h: In function ‘timeval_to_jiffies’:
/usr/src/linux-2.6.16/include/linux/jiffies.h:350: error: called object ‘u64’ is not a function
/usr/src/linux-2.6.16/include/linux/jiffies.h:350: error: called object ‘u64’ is not a function
/usr/src/linux-2.6.16/include/linux/jiffies.h:350: error: ‘NSEC_PER_SEC’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:351: error: called object ‘u64’ is not a function
/usr/src/linux-2.6.16/include/linux/jiffies.h:351: error: called object ‘u64’ is not a function
/usr/src/linux-2.6.16/include/linux/jiffies.h:354: error: syntax error before ‘sec’
/usr/src/linux-2.6.16/include/linux/jiffies.h:354: error: syntax error before ‘NSEC_PER_SEC’
/usr/src/linux-2.6.16/include/linux/jiffies.h:354: error: called object ‘u64’ is not a function
/usr/src/linux-2.6.16/include/linux/jiffies.h:354: error: syntax error before ‘)’ token
/usr/src/linux-2.6.16/include/linux/jiffies.h: In function ‘jiffies_to_timeval’:
/usr/src/linux-2.6.16/include/linux/jiffies.h:366: error: syntax error before ‘nsec’
/usr/src/linux-2.6.16/include/linux/jiffies.h:369: error: ‘nsec’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:369: error: ‘NSEC_PER_SEC’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:370: error: ‘NSEC_PER_USEC’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:379:41: error: division by zero in #if
/usr/src/linux-2.6.16/include/linux/jiffies.h:379:42: error: division by zero in #if
/usr/src/linux-2.6.16/include/linux/jiffies.h: In function ‘jiffies_to_clock_t’:
/usr/src/linux-2.6.16/include/linux/jiffies.h:382: error: syntax error before ‘tmp’
/usr/src/linux-2.6.16/include/linux/jiffies.h:383: error: ‘NSEC_PER_SEC’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:383: error: ‘USER_HZ’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:383: error: ‘tmp’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:383: error: invalid lvalue in asm output 0
/usr/src/linux-2.6.16/include/linux/jiffies.h:390:18: error: division by zero in #if
/usr/src/linux-2.6.16/include/linux/jiffies.h: In function ‘clock_t_to_jiffies’:
/usr/src/linux-2.6.16/include/linux/jiffies.h:395: error: syntax error before ‘jif’
/usr/src/linux-2.6.16/include/linux/jiffies.h:398: error: ‘USER_HZ’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:402: error: ‘jif’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:402: error: syntax error before numeric constant
/usr/src/linux-2.6.16/include/linux/jiffies.h:403: error: invalid lvalue in asm output 0
/usr/src/linux-2.6.16/include/linux/jiffies.h: At top level:
/usr/src/linux-2.6.16/include/linux/jiffies.h:408: error: syntax error before ‘jiffies_64_to_clock_t’
/usr/src/linux-2.6.16/include/linux/jiffies.h:408: error: syntax error before ‘x’
/usr/src/linux-2.6.16/include/linux/jiffies.h:410:41: error: division by zero in #if
/usr/src/linux-2.6.16/include/linux/jiffies.h:410:42: error: division by zero in #if
/usr/src/linux-2.6.16/include/linux/jiffies.h: In function ‘jiffies_64_to_clock_t’:
/usr/src/linux-2.6.16/include/linux/jiffies.h:418: error: ‘x’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:419: error: ‘NSEC_PER_SEC’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:419: error: ‘USER_HZ’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:419: error: invalid lvalue in asm output 0
/usr/src/linux-2.6.16/include/linux/jiffies.h: At top level:
/usr/src/linux-2.6.16/include/linux/jiffies.h:424: error: syntax error before ‘nsec_to_clock_t’
/usr/src/linux-2.6.16/include/linux/jiffies.h:424: error: syntax error before ‘x’
/usr/src/linux-2.6.16/include/linux/jiffies.h:426:28: error: division by zero in #if
/usr/src/linux-2.6.16/include/linux/jiffies.h: In function ‘nsec_to_clock_t’:
/usr/src/linux-2.6.16/include/linux/jiffies.h:427: error: ‘NSEC_PER_SEC’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:427: error: ‘USER_HZ’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:427: error: ‘x’ undeclared (first use in this function)
/usr/src/linux-2.6.16/include/linux/jiffies.h:427: error: invalid lvalue in asm output 0
In file included from /usr/src/linux-2.6.16/include/linux/cpumask.h:86,
                 from /usr/src/linux-2.6.16/include/linux/sched.h:15,
                 from /usr/src/linux-2.6.16/include/linux/module.h:10,
                 from hello.c:2:



LOTS OF STUFF HERE!!!!!!!







hello.c: In function ‘hello_init’:
hello.c:9: error: ‘KERN_ALERT’ undeclared (first use in this function)
hello.c:9: error: syntax error before string constant
hello.c: In function ‘hello_exit’:
hello.c:15: error: ‘KERN_ALERT’ undeclared (first use in this function)
hello.c:15: error: syntax error before string constant
 
Old 04-27-2006, 02:09 PM   #2
antdengineer
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Original Poster
Rep: Reputation: 0
Please!

PLEASE! There must be someone who knows about this stuff that I can talk to.
 
Old 04-27-2006, 02:52 PM   #3
Vagrant
Member
 
Registered: Nov 2001
Posts: 75

Rep: Reputation: 15
No, put the hello.c in your home dir or somewhere, not in the true kernel source. If its in your homedir, cd into the home dir and do this:

make -C /usr/src/linux-2.6.16/ M=`pwd` modules

Last edited by Vagrant; 04-27-2006 at 03:00 PM.
 
Old 04-27-2006, 03:10 PM   #4
antdengineer
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Original Poster
Rep: Reputation: 0
Hey, thanks for the reply. THe command that you posted is used to make the actual module from the object file, am I correct? My problem is that I cant make the object file itself using my program and the kernel source. The command that I used above was run on hello.c in my home directory as well as the kernel directory and both dont work. How is it that I compile my hello.c into an object file without such errors?
 
Old 04-27-2006, 03:15 PM   #5
Vagrant
Member
 
Registered: Nov 2001
Posts: 75

Rep: Reputation: 15
Did you use the command I posted?
 
Old 04-27-2006, 03:21 PM   #6
antdengineer
LQ Newbie
 
Registered: Apr 2006
Posts: 4

Original Poster
Rep: Reputation: 0
.....My apologies. Um, yes that worked quite well. What exactly does that command do, and how does it know what c file to compile? Oh and THANKS!

Oh, yea, and I understand that its using the make command and the appropriate Makefile. But I dont understand how this make syntax works.

Last edited by antdengineer; 04-27-2006 at 03:26 PM.
 
Old 04-27-2006, 03:53 PM   #7
Vagrant
Member
 
Registered: Nov 2001
Posts: 75

Rep: Reputation: 15
Its using the make file in the kernel source directory. Since your file is ".c," and you did "make modules," all the .c files that are supplied in the "M=" directory, for which you supplsed `pwd1, are treated as modules. There is a discussion in that book about this in the section called "Compiling and Loading Modules" or something like that.

Glad to help.
 
Old 09-26-2009, 11:59 PM   #8
Varad
LQ Newbie
 
Registered: Sep 2009
Distribution: ubuntu-9.04
Posts: 1

Rep: Reputation: 0
Hi,
I am using ubuntu-9.04 and have compiled kernel 2.6.28.10.
I tried to compile my "hello-world" module using the above command
I am still getting the following errors.

Code:
"make -C /usr/src/linux" M=`pwd`

 In file included from include/linux/types.h:11,
                 from include/linux/prefetch.h:13,
                 from include/linux/list.h:6,
                 from include/linux/module.h:9,
                 from /home/varad/hello.c:2:
include/linux/posix_types.h:47:29: error: asm/posix_types.h: No such file or directory
In file included from include/linux/prefetch.h:13,
                 from include/linux/list.h:6,
                 from include/linux/module.h:9,
                 from /home/varad/hello.c:2:
include/linux/types.h:12:23: error: asm/types.h: No such file or directory
In file included from include/linux/prefetch.h:13,
                 from include/linux/list.h:6,
                 from include/linux/module.h:9,
                 from /home/varad/hello.c:2:
include/linux/types.h:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__kernel_dev_t’
include/linux/types.h:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘dev_t’
include/linux/types.h:20: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ino_t’
include/linux/types.h:21: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘mode_t’
include/linux/types.h:22: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘nlink_t’
include/linux/types.h:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘off_t’
include/linux/types.h:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pid_t’
include/linux/types.h:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘daddr_t’
include/linux/types.h:27: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘suseconds_t’
include/linux/types.h:28: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘timer_t’
include/linux/types.h:29: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘clockid_t’
include/linux/types.h:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uid_t’
include/linux/types.h:36: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘gid_t’
include/linux/types.h:37: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uid16_t’
include/linux/types.h:38: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘gid16_t’
include/linux/types.h:44: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘old_uid_t’
include/linux/types.h:45: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘old_gid_t’
include/linux/types.h:57: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘loff_t’
include/linux/types.h:66: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘size_t’
include/linux/types.h:71: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ssize_t’
include/linux/types.h:76: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ptrdiff_t’
include/linux/types.h:81: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘time_t’
include/linux/types.h:86: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘clock_t’
include/linux/types.h:91: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘caddr_t’
include/linux/types.h:109: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘u_int8_t’
include/linux/types.h:110: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int8_t’
include/linux/types.h:111: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘u_int16_t’
include/linux/types.h:112: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int16_t’
include/linux/types.h:113: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘u_int32_t’
include/linux/types.h:114: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int32_t’
include/linux/types.h:118: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint8_t’
include/linux/types.h:119: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint16_t’
include/linux/types.h:120: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint32_t’
include/linux/types.h:123: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint64_t’
include/linux/types.h:124: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘u_int64_t’
include/linux/types.h:125: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int64_t’
include/linux/types.h:140: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘sector_t’
include/linux/types.h:149: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘blkcnt_t’
include/linux/types.h:180: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__le16’
include/linux/types.h:181: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__be16’
include/linux/types.h:182: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__le32’
include/linux/types.h:183: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__be32’
include/linux/types.h:185: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__le64’
include/linux/types.h:186: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__be64’
include/linux/types.h:188: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__sum16’
include/linux/types.h:189: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__wsum’
include/linux/types.h:198: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘phys_addr_t’
include/linux/types.h:201: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘resource_size_t’
include/linux/types.h:204: error: expected specifier-qualifier-list before ‘__kernel_daddr_t’
In file included from include/linux/list.h:6,
                 from include/linux/module.h:9,
                 from /home/varad/hello.c:2:
include/linux/prefetch.h:14:27: error: asm/processor.h: No such file or directory
include/linux/prefetch.h:15:23: error: asm/cache.h: No such file or directory
In file included from include/linux/list.h:6,
                 from include/linux/module.h:9,
                 from /home/varad/hello.c:2:
include/linux/prefetch.h:53: error: expected declaration specifiers or ‘...’ before ‘size_t’
In file included from include/linux/module.h:9,
                 from /home/varad/hello.c:2:
include/linux/list.h:7:24: error: asm/system.h: No such file or directory
In file included from include/linux/module.h:10,
                 from /home/varad/hello.c:2:
include/linux/stat.h:6:22: error: asm/stat.h: No such file or directory
In file included from include/linux/kernel.h:11,
                 from include/linux/cache.h:4,
                 from include/linux/time.h:7,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/varad/hello.c:2:
include/linux/linkage.h:5:25: error: asm/linkage.h: No such file or directory
In file included from include/asm/bitops.h:12,
                 from include/linux/bitops.h:17,
                 from include/linux/kernel.h:15,
                 from include/linux/cache.h:4,
                 from include/linux/time.h:7,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/varad/hello.c:2:
include/asm-generic/bitops/atomic.h:7:26: error: asm/spinlock.h: No such file or directory
In file included from include/asm/bitops.h:12,
                 from include/linux/bitops.h:17,
                 from include/linux/kernel.h:15,
                 from include/linux/cache.h:4,
                 from include/linux/time.h:7,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/varad/hello.c:2:
include/asm-generic/bitops/atomic.h:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__atomic_hash’
include/asm-generic/bitops/atomic.h: In function ‘set_bit’:
include/asm-generic/bitops/atomic.h:66: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:66: error: (Each undeclared identifier is reported only once
include/asm-generic/bitops/atomic.h:66: error: for each function it appears in.)
include/asm-generic/bitops/atomic.h:70: error: ‘raw_spinlock_t’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:70: error: ‘s’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:70: error: ‘__atomic_hash’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:70: error: ‘L1_CACHE_BYTES’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:70: error: implicit declaration of function ‘local_irq_save’
include/asm-generic/bitops/atomic.h:70: error: implicit declaration of function ‘__raw_spin_lock’
include/asm-generic/bitops/atomic.h:72: error: implicit declaration of function ‘__raw_spin_unlock’
include/asm-generic/bitops/atomic.h:72: error: implicit declaration of function ‘local_irq_restore’
include/asm-generic/bitops/atomic.h: In function ‘clear_bit’:
include/asm-generic/bitops/atomic.h:87: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:91: error: ‘raw_spinlock_t’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:91: error: ‘s’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:91: error: ‘__atomic_hash’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:91: error: ‘L1_CACHE_BYTES’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h: In function ‘change_bit’:
include/asm-generic/bitops/atomic.h:108: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:112: error: ‘raw_spinlock_t’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:112: error: ‘s’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:112: error: ‘__atomic_hash’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:112: error: ‘L1_CACHE_BYTES’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h: In function ‘test_and_set_bit’:
include/asm-generic/bitops/atomic.h:128: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:133: error: ‘raw_spinlock_t’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:133: error: ‘s’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:133: error: ‘__atomic_hash’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:133: error: ‘L1_CACHE_BYTES’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h: In function ‘test_and_clear_bit’:
include/asm-generic/bitops/atomic.h:152: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:157: error: ‘raw_spinlock_t’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:157: error: ‘s’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:157: error: ‘__atomic_hash’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:157: error: ‘L1_CACHE_BYTES’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h: In function ‘test_and_change_bit’:
include/asm-generic/bitops/atomic.h:175: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:180: error: ‘raw_spinlock_t’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:180: error: ‘s’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:180: error: ‘__atomic_hash’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:180: error: ‘L1_CACHE_BYTES’ undeclared (first use in this function)
In file included from include/asm/bitops.h:13,
                 from include/linux/bitops.h:17,
                 from include/linux/kernel.h:15,
                 from include/linux/cache.h:4,
                 from include/linux/time.h:7,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/varad/hello.c:2:
include/asm-generic/bitops/non-atomic.h: In function ‘__set_bit’:
include/asm-generic/bitops/non-atomic.h:17: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/non-atomic.h: In function ‘__clear_bit’:
include/asm-generic/bitops/non-atomic.h:25: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/non-atomic.h: In function ‘__change_bit’:
include/asm-generic/bitops/non-atomic.h:42: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/non-atomic.h: In function ‘__test_and_set_bit’:
include/asm-generic/bitops/non-atomic.h:59: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/non-atomic.h: In function ‘__test_and_clear_bit’:
include/asm-generic/bitops/non-atomic.h:78: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/non-atomic.h: In function ‘__test_and_change_bit’:
include/asm-generic/bitops/non-atomic.h:90: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/non-atomic.h: In function ‘test_bit’:
include/asm-generic/bitops/non-atomic.h:105: error: ‘BITS_PER_LONG’ undeclared (first use in this function)

...And So on...
Help please.
Varad
 
Old 09-28-2009, 01:40 PM   #9
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by Varad View Post
Hi,
I am using ubuntu-9.04 and have compiled kernel 2.6.28.10.
I tried to compile my "hello-world" module using the above command
I am still getting the following errors.

Code:
"make -C /usr/src/linux" M=`pwd`

 In file included from include/linux/types.h:11,
                 from include/linux/prefetch.h:13,
                 from include/linux/list.h:6,
                 from include/linux/module.h:9,
                 from /home/varad/hello.c:2:
include/linux/posix_types.h:47:29: error: asm/posix_types.h: No such file or directory
In file included from include/linux/prefetch.h:13,
                 from include/linux/list.h:6,
                 from include/linux/module.h:9,
                 from /home/varad/hello.c:2:
include/linux/types.h:12:23: error: asm/types.h: No such file or directory
In file included from include/linux/prefetch.h:13,
                 from include/linux/list.h:6,
                 from include/linux/module.h:9,
                 from /home/varad/hello.c:2:
include/linux/types.h:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__kernel_dev_t’
include/linux/types.h:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘dev_t’
include/linux/types.h:20: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ino_t’
include/linux/types.h:21: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘mode_t’
include/linux/types.h:22: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘nlink_t’
include/linux/types.h:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘off_t’
include/linux/types.h:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pid_t’
include/linux/types.h:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘daddr_t’
include/linux/types.h:27: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘suseconds_t’
include/linux/types.h:28: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘timer_t’
include/linux/types.h:29: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘clockid_t’
include/linux/types.h:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uid_t’
include/linux/types.h:36: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘gid_t’
include/linux/types.h:37: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uid16_t’
include/linux/types.h:38: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘gid16_t’
include/linux/types.h:44: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘old_uid_t’
include/linux/types.h:45: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘old_gid_t’
include/linux/types.h:57: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘loff_t’
include/linux/types.h:66: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘size_t’
include/linux/types.h:71: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ssize_t’
include/linux/types.h:76: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ptrdiff_t’
include/linux/types.h:81: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘time_t’
include/linux/types.h:86: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘clock_t’
include/linux/types.h:91: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘caddr_t’
include/linux/types.h:109: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘u_int8_t’
include/linux/types.h:110: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int8_t’
include/linux/types.h:111: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘u_int16_t’
include/linux/types.h:112: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int16_t’
include/linux/types.h:113: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘u_int32_t’
include/linux/types.h:114: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int32_t’
include/linux/types.h:118: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint8_t’
include/linux/types.h:119: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint16_t’
include/linux/types.h:120: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint32_t’
include/linux/types.h:123: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘uint64_t’
include/linux/types.h:124: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘u_int64_t’
include/linux/types.h:125: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int64_t’
include/linux/types.h:140: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘sector_t’
include/linux/types.h:149: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘blkcnt_t’
include/linux/types.h:180: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__le16’
include/linux/types.h:181: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__be16’
include/linux/types.h:182: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__le32’
include/linux/types.h:183: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__be32’
include/linux/types.h:185: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__le64’
include/linux/types.h:186: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__be64’
include/linux/types.h:188: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__sum16’
include/linux/types.h:189: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__wsum’
include/linux/types.h:198: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘phys_addr_t’
include/linux/types.h:201: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘resource_size_t’
include/linux/types.h:204: error: expected specifier-qualifier-list before ‘__kernel_daddr_t’
In file included from include/linux/list.h:6,
                 from include/linux/module.h:9,
                 from /home/varad/hello.c:2:
include/linux/prefetch.h:14:27: error: asm/processor.h: No such file or directory
include/linux/prefetch.h:15:23: error: asm/cache.h: No such file or directory
In file included from include/linux/list.h:6,
                 from include/linux/module.h:9,
                 from /home/varad/hello.c:2:
include/linux/prefetch.h:53: error: expected declaration specifiers or ‘...’ before ‘size_t’
In file included from include/linux/module.h:9,
                 from /home/varad/hello.c:2:
include/linux/list.h:7:24: error: asm/system.h: No such file or directory
In file included from include/linux/module.h:10,
                 from /home/varad/hello.c:2:
include/linux/stat.h:6:22: error: asm/stat.h: No such file or directory
In file included from include/linux/kernel.h:11,
                 from include/linux/cache.h:4,
                 from include/linux/time.h:7,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/varad/hello.c:2:
include/linux/linkage.h:5:25: error: asm/linkage.h: No such file or directory
In file included from include/asm/bitops.h:12,
                 from include/linux/bitops.h:17,
                 from include/linux/kernel.h:15,
                 from include/linux/cache.h:4,
                 from include/linux/time.h:7,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/varad/hello.c:2:
include/asm-generic/bitops/atomic.h:7:26: error: asm/spinlock.h: No such file or directory
In file included from include/asm/bitops.h:12,
                 from include/linux/bitops.h:17,
                 from include/linux/kernel.h:15,
                 from include/linux/cache.h:4,
                 from include/linux/time.h:7,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/varad/hello.c:2:
include/asm-generic/bitops/atomic.h:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__atomic_hash’
include/asm-generic/bitops/atomic.h: In function ‘set_bit’:
include/asm-generic/bitops/atomic.h:66: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:66: error: (Each undeclared identifier is reported only once
include/asm-generic/bitops/atomic.h:66: error: for each function it appears in.)
include/asm-generic/bitops/atomic.h:70: error: ‘raw_spinlock_t’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:70: error: ‘s’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:70: error: ‘__atomic_hash’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:70: error: ‘L1_CACHE_BYTES’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:70: error: implicit declaration of function ‘local_irq_save’
include/asm-generic/bitops/atomic.h:70: error: implicit declaration of function ‘__raw_spin_lock’
include/asm-generic/bitops/atomic.h:72: error: implicit declaration of function ‘__raw_spin_unlock’
include/asm-generic/bitops/atomic.h:72: error: implicit declaration of function ‘local_irq_restore’
include/asm-generic/bitops/atomic.h: In function ‘clear_bit’:
include/asm-generic/bitops/atomic.h:87: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:91: error: ‘raw_spinlock_t’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:91: error: ‘s’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:91: error: ‘__atomic_hash’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:91: error: ‘L1_CACHE_BYTES’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h: In function ‘change_bit’:
include/asm-generic/bitops/atomic.h:108: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:112: error: ‘raw_spinlock_t’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:112: error: ‘s’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:112: error: ‘__atomic_hash’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:112: error: ‘L1_CACHE_BYTES’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h: In function ‘test_and_set_bit’:
include/asm-generic/bitops/atomic.h:128: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:133: error: ‘raw_spinlock_t’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:133: error: ‘s’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:133: error: ‘__atomic_hash’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:133: error: ‘L1_CACHE_BYTES’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h: In function ‘test_and_clear_bit’:
include/asm-generic/bitops/atomic.h:152: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:157: error: ‘raw_spinlock_t’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:157: error: ‘s’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:157: error: ‘__atomic_hash’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:157: error: ‘L1_CACHE_BYTES’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h: In function ‘test_and_change_bit’:
include/asm-generic/bitops/atomic.h:175: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:180: error: ‘raw_spinlock_t’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:180: error: ‘s’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:180: error: ‘__atomic_hash’ undeclared (first use in this function)
include/asm-generic/bitops/atomic.h:180: error: ‘L1_CACHE_BYTES’ undeclared (first use in this function)
In file included from include/asm/bitops.h:13,
                 from include/linux/bitops.h:17,
                 from include/linux/kernel.h:15,
                 from include/linux/cache.h:4,
                 from include/linux/time.h:7,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/varad/hello.c:2:
include/asm-generic/bitops/non-atomic.h: In function ‘__set_bit’:
include/asm-generic/bitops/non-atomic.h:17: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/non-atomic.h: In function ‘__clear_bit’:
include/asm-generic/bitops/non-atomic.h:25: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/non-atomic.h: In function ‘__change_bit’:
include/asm-generic/bitops/non-atomic.h:42: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/non-atomic.h: In function ‘__test_and_set_bit’:
include/asm-generic/bitops/non-atomic.h:59: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/non-atomic.h: In function ‘__test_and_clear_bit’:
include/asm-generic/bitops/non-atomic.h:78: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/non-atomic.h: In function ‘__test_and_change_bit’:
include/asm-generic/bitops/non-atomic.h:90: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
include/asm-generic/bitops/non-atomic.h: In function ‘test_bit’:
include/asm-generic/bitops/non-atomic.h:105: error: ‘BITS_PER_LONG’ undeclared (first use in this function)

...And So on...
Help please.
Varad
maybe you used something that isnt allowed in the module
without the code its impossable to tell
 
Old 12-04-2010, 04:07 AM   #10
ackitkeys
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Rep: Reputation: 0
this worked for me

Makefile
Code:
obj-m = hello.o
KVERSION = $(shell uname -r)
all:
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
hello.c
Code:
#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);
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mkinitrd failed with message "no module raid0 found for kernel 2.6.9" ythevenot Red Hat 3 12-07-2004 09:15 PM
"Invalid module format" after FULL kernel recompile RedDwarf Linux - General 6 08-07-2004 07:46 PM
kernel 2.6.0 debian "No module symbols loaded - kernel modules not enabled." toovato Linux - General 2 01-07-2004 07:56 PM
error loading a kernel module, "compiled using gcc2" taozilla Linux - Software 0 11-21-2003 03:23 PM
Compiling a kernel module results in "insmod" version mvega Linux - General 2 07-30-2003 09:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration