Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I wrote a very simple kernel programming source code:

#include <linux/kernel.h>
#include <linux/fcntl.h>
#include <linux/init.h>

static int __init(void){
    sys_open("ee.c", O_RDONLY);

but because kernel sources (which is really executed now) is on home folder, below errors occurred. Even though I made symbolic links like that.

rm -rf /usr/include/linux
rm -rf /usr/include/asm

ln -s /home/linux-2.6.21/include/linux /usr/include/linux
ln -s /home/linux-2.6.21/include/asm-i386 /usr/include/asm

 

In file included from /usr/include/asm/fcntl.h:1,  
             from /usr/include/linux/fcntl.h:4,  
             from v.c:2:  
/usr/include/asm-generic/fcntl.h:120: error: expected specifier-qualifier-list before ‘off_t’  
/usr/include/asm-generic/fcntl.h:143: error: expected specifier-qualifier-list before ‘loff_t’  

What do I need to do before using kernel headers which is different folder with /usr/include and why this type errors occurred?

i made also

rm -rf /usr/include/asm
ln -s /home/linux-2.6.21/include/asm-i386 /usr/include/asm

and #include <linux/syscall.h> i was stucked....
that is full error message.. i think the kernel header files are particulary disinformationed..

In file included from /usr/include/linux/syscalls.h:61,
                 from vv.c:4:
/usr/include/linux/list.h:959:2: warning: #warning "don't include kernel headers in userspace"
In file included from /usr/include/asm/siginfo.h:4,
                 from /usr/include/linux/syscalls.h:64,
                 from vv.c:4:
/usr/include/asm-generic/siginfo.h:75: error: expected specifier-qualifier-list before ‘clock_t’
In file included from /usr/include/asm/signal.h:5,
                 from /usr/include/linux/syscalls.h:65,
                 from vv.c:4:
/usr/include/linux/time.h:12: error: redefinition of ‘struct timespec’
/usr/include/linux/time.h:18: error: redefinition of ‘struct timeval’
In file included from /usr/include/linux/syscalls.h:65,
                 from vv.c:4:
/usr/include/asm/signal.h:32: error: conflicting types for ‘sigset_t’
/usr/include/sys/select.h:38: error: previous declaration of ‘sigset_t’ was here
In file included from /usr/include/linux/syscalls.h:66,
                 from vv.c:4:
/usr/include/linux/quota.h:47: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘dq_data_lock’
In file included from /usr/include/asm/processor.h:17,
                 from /usr/include/asm/atomic.h:5,
                 from /usr/include/linux/key.h:22,
                 from /usr/include/linux/syscalls.h:67,
                 from vv.c:4:
/usr/include/asm/msr.h:90: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/msr.h:90: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/msr.h:90: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/msr.h: In function ‘rdmsr_on_cpu’:
/usr/include/asm/msr.h:92: error: ‘l’ undeclared (first use in this function)
/usr/include/asm/msr.h:92: error: (Each undeclared identifier is reported only once
/usr/include/asm/msr.h:92: error: for each function it appears in.)
/usr/include/asm/msr.h:92: error: ‘h’ undeclared (first use in this function)
/usr/include/asm/msr.h:92: error: ‘msr_no’ undeclared (first use in this function)
/usr/include/asm/msr.h:92: error: invalid lvalue in asm output 0
/usr/include/asm/msr.h:92: error: invalid lvalue in asm output 1
/usr/include/asm/msr.h: At top level:
/usr/include/asm/msr.h:94: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/msr.h:94: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/msr.h:94: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/msr.h: In function ‘wrmsr_on_cpu’:
/usr/include/asm/msr.h:96: error: ‘msr_no’ undeclared (first use in this function)
/usr/include/asm/msr.h:96: error: ‘l’ undeclared (first use in this function)
/usr/include/asm/msr.h:96: error: ‘h’ undeclared (first use in this function)
In file included from /usr/include/asm/processor.h:18,
                 from /usr/include/asm/atomic.h:5,
                 from /usr/include/linux/key.h:22,
                 from /usr/include/linux/syscalls.h:67,
                 from vv.c:4:
/usr/include/asm/system.h: At top level:
/usr/include/asm/system.h:346: error: expected declaration specifiers or ‘...’ before ‘u8’
/usr/include/asm/system.h:346: error: expected declaration specifiers or ‘...’ before ‘u8’
/usr/include/asm/system.h:347: error: expected declaration specifiers or ‘...’ before ‘u16’
/usr/include/asm/system.h:347: error: expected declaration specifiers or ‘...’ before ‘u16’
/usr/include/asm/system.h:348: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/system.h:348: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/system.h: In function ‘cmpxchg_386’:
/usr/include/asm/system.h:355: error: too many arguments to function ‘cmpxchg_386_u8’
/usr/include/asm/system.h:357: error: too many arguments to function ‘cmpxchg_386_u16’
/usr/include/asm/system.h:359: error: too many arguments to function ‘cmpxchg_386_u32’
In file included from /usr/include/linux/cpumask.h:86,
                 from /usr/include/asm/processor.h:22,
                 from /usr/include/asm/atomic.h:5,
                 from /usr/include/linux/key.h:22,
                 from /usr/include/linux/syscalls.h:67,
                 from vv.c:4:
/usr/include/linux/bitmap.h: In function ‘bitmap_zero’:
/usr/include/linux/bitmap.h:134: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_fill’:
/usr/include/linux/bitmap.h:149: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_copy’:
/usr/include/linux/bitmap.h:155: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_and’:
/usr/include/linux/bitmap.h:166: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_or’:
/usr/include/linux/bitmap.h:175: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_xor’:
/usr/include/linux/bitmap.h:184: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_andnot’:
/usr/include/linux/bitmap.h:193: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_complement’:
/usr/include/linux/bitmap.h:202: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_equal’:
/usr/include/linux/bitmap.h:211: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_intersects’:
/usr/include/linux/bitmap.h:220: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_subset’:
/usr/include/linux/bitmap.h:229: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_empty’:
/usr/include/linux/bitmap.h:237: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_full’:
/usr/include/linux/bitmap.h:245: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_weight’:
/usr/include/linux/bitmap.h:253: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_shift_right’:
/usr/include/linux/bitmap.h:261: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_shift_left’:
/usr/include/linux/bitmap.h:270: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
In file included from /usr/include/asm/processor.h:22,
                 from /usr/include/asm/atomic.h:5,
                 from /usr/include/linux/key.h:22,
                 from /usr/include/linux/syscalls.h:67,
                 from vv.c:4:
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:88: error: expected specifier-qualifier-list before ‘DECLARE_BITMAP’
/usr/include/linux/cpumask.h: In function ‘__cpu_set’:
/usr/include/linux/cpumask.h:94: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpu_clear’:
/usr/include/linux/cpumask.h:100: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_setall’:
/usr/include/linux/cpumask.h:106: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_clear’:
/usr/include/linux/cpumask.h:112: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpu_test_and_set’:
/usr/include/linux/cpumask.h:121: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_and’:
/usr/include/linux/cpumask.h:128: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:128: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:128: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_or’:
/usr/include/linux/cpumask.h:135: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:135: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:135: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_xor’:
/usr/include/linux/cpumask.h:142: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:142: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:142: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_andnot’:
/usr/include/linux/cpumask.h:150: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:150: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:150: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_complement’:
/usr/include/linux/cpumask.h:157: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:157: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_equal’:
/usr/include/linux/cpumask.h:164: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:164: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_intersects’:
/usr/include/linux/cpumask.h:171: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:171: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_subset’:
/usr/include/linux/cpumask.h:178: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:178: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_empty’:
/usr/include/linux/cpumask.h:184: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_full’:
/usr/include/linux/cpumask.h:190: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_weight’:
/usr/include/linux/cpumask.h:196: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_shift_right’:
/usr/include/linux/cpumask.h:204: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:204: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_shift_left’:
/usr/include/linux/cpumask.h:212: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:212: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpumask_scnprintf’:
/usr/include/linux/cpumask.h:273: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpumask_parse_user’:
/usr/include/linux/cpumask.h:281: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpulist_scnprintf’:
/usr/include/linux/cpumask.h:289: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpulist_parse’:
/usr/include/linux/cpumask.h:295: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpu_remap’:
/usr/include/linux/cpumask.h:303: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:303: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_remap’:
/usr/include/linux/cpumask.h:311: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:311: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:311: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:311: error: ‘cpumask_t’ has no member named ‘bits’
In file included from /usr/include/asm/atomic.h:5,
                 from /usr/include/linux/key.h:22,
                 from /usr/include/linux/syscalls.h:67,
                 from vv.c:4:
/usr/include/asm/processor.h: At top level:
/usr/include/asm/processor.h:82: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)
/usr/include/asm/processor.h:82: error: requested alignment is not a constant
In file included from vv.c:4:
/usr/include/linux/syscalls.h:114: error: expected ‘)’ before ‘*’ token
/usr/include/linux/syscalls.h:115: error: expected declaration specifiers or ‘...’ before ‘old_sigset_t’
/usr/include/linux/syscalls.h:116: error: expected declaration specifiers or ‘...’ before ‘old_sigset_t’
/usr/include/linux/syscalls.h:178: error: expected ‘)’ before ‘*’ token
/usr/include/linux/syscalls.h:394: error: expected ‘)’ before ‘cookie64’
/usr/include/linux/syscalls.h:474: error: expected ‘)’ before ‘mqdes’
/usr/include/linux/syscalls.h:475: error: expected ‘)’ before ‘mqdes’
/usr/include/linux/syscalls.h:476: error: expected ‘)’ before ‘mqdes’
/usr/include/linux/syscalls.h:477: error: expected ‘)’ before ‘mqdes’
/usr/include/linux/syscalls.h:507: error: expected declaration specifiers or ‘...’ before ‘key_serial_t’
/usr/include/linux/syscalls.h:512: error: expected declaration specifiers or ‘...’ before ‘key_serial_t’
/usr/include/linux/syscalls.h:546: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/linux/syscalls.h:547: error: expected declaration specifiers or ‘...’ before ‘u32’
vv.c: In function ‘init’:
vv.c:7: error: too few arguments to function ‘sys_open’
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

The asm-generic headers also come from the Linux kernel, so you've essentially mixed some of the sanitised headers from /usr/include with some from the source in your home directory.

If you are writing a user space program, you may as well just use the sanitised headers that come with the distro: the only information they are missing are the parts necessary to compile code that is intended to run inside the kernel.

To recover the files you deleted, remove the two symlinks you created and then run apt-get install --reinstall linux-libc-dev.

Alternatively, if you need to use unsanitised kernel headers for that particular kernel version, just pass -I/home/linux-2.6.21/include to the compiler so it will pick those headers in preference to the system installed ones.

share|improve this answer
    
the instruction apt-get install --reinstall linux-libc-dev is very useful! thanks! but i was stucked because of odd error messages, after making symlink and including linux/syscall.h –  KayKay May 16 '11 at 12:54
    
Okay. <linux/syscalls.h> looks like it isn't intended to be included in user space code, as the "don't include kernel headers in userspace" error indicates. The user space interface is through either the syscall() or _syscall() interfaces (both have man pages), although you may as well just use the C library wrappers: you're much less likely to make a mistake that way. –  James Henstridge May 16 '11 at 14:55
    
but when i search through google, i can find many codes that use <linux/syscall.h>,<linux/modules.h>... applying same kernel headers rule, how to they use kernel headers? –  KayKay May 17 '11 at 4:03
    
Presumably the code you found was kernel mode (i.e. code linked directly into the Linux kernel) rather than user mode (i.e. applications running on top of the Linux kernel). –  James Henstridge May 17 '11 at 5:43
    
yes, that was mistake! thanks a lot:) –  KayKay May 17 '11 at 9:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.