how to compile basic hello.c kernel program Suse Linux 9.3
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how to compile basic hello.c kernel program Suse Linux 9.3
Hi,
I am trying to compile the simplest hello.c linux program kernel program under Suse Linux 9.3. Below is my program, and below that is the compile errors I am getting. Do I need to install something else? I thought I had brought in all the source code but... I was able to build my own Linux Kernel and boot from it, but I can't seem to be able to build a simple program. Can anyone tell what might be missing, and why I am getting the compile errors?
---
psullivan@linux:~> gcc hello.c
In file included from /usr/include/asm/system.h:4,
from /usr/include/linux/jiffies.h:8,
from /usr/include/linux/sched.h:12,
from /usr/include/linux/module.h:9,
from hello.c:10:
/usr/include/asm-x86_64/system.h: In function `__cmpxchg':
/usr/include/asm-x86_64/system.h:249: error: `LOCK_PREFIX' undeclared (first use in this function)
/usr/include/asm-x86_64/system.h:249: error: (Each undeclared identifier is reported only once
/usr/include/asm-x86_64/system.h:249: error: for each function it appears in.)
/usr/include/asm-x86_64/system.h:249: error: syntax error before string constant
/usr/include/asm-x86_64/system.h:255: error: syntax error before string constant
/usr/include/asm-x86_64/system.h:261: error: syntax error before string constant
/usr/include/asm-x86_64/system.h:267: error: syntax error before string constant
In file included from /usr/include/linux/sched.h:12,
from /usr/include/linux/module.h:9,
from hello.c:10:
/usr/include/linux/jiffies.h: At top level:
/usr/include/linux/jiffies.h:16: error: syntax error before "jiffies_64"
/usr/include/linux/jiffies.h:20: error: syntax error before "get_jiffies_64"
In file included from /usr/include/linux/cpumask.h:78,
from /usr/include/linux/sched.h:15,
from /usr/include/linux/module.h:9,
from hello.c:10:
/usr/include/linux/bitmap.h: In function `bitmap_zero':
/usr/include/linux/bitmap.h:113: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_fill':
/usr/include/linux/bitmap.h:128: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_copy':
/usr/include/linux/bitmap.h:134: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_and':
/usr/include/linux/bitmap.h:145: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_or':
/usr/include/linux/bitmap.h:154: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_xor':
/usr/include/linux/bitmap.h:163: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_andnot':
/usr/include/linux/bitmap.h:172: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_complement':
/usr/include/linux/bitmap.h:181: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_equal':
/usr/include/linux/bitmap.h:190: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_intersects':
/usr/include/linux/bitmap.h:199: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_subset':
/usr/include/linux/bitmap.h:208: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_empty':
/usr/include/linux/bitmap.h:216: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_full':
/usr/include/linux/bitmap.h:224: 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:238: 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:247: error: `BITS_PER_LONG' undeclared (first use in this function)
In file included from /usr/include/linux/sched.h:15,
from /usr/include/linux/module.h:9,
from hello.c:10:
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:81: error: syntax error before "DECLARE_BITMAP"
/usr/include/linux/cpumask.h:82: error: syntax error before "_unused_cpumask_arg_"
/usr/include/linux/cpumask.h:85: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpu_set':
/usr/include/linux/cpumask.h:87: error: `cpu' undeclared (first use in this function)
/usr/include/linux/cpumask.h:87: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:91: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpu_clear':
/usr/include/linux/cpumask.h:93: error: `cpu' undeclared (first use in this function)
/usr/include/linux/cpumask.h:93: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:97: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_setall':
/usr/include/linux/cpumask.h:99: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:99: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:103: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_clear':
/usr/include/linux/cpumask.h:105: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:105: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:112: error: syntax error before "cpumask_t"
/usr/include/linux/cpumask.h: In function `__cpu_test_and_set':
/usr/include/linux/cpumask.h:114: error: `cpu' undeclared (first use in this function)
/usr/include/linux/cpumask.h:114: error: `addr' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:118: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_and':
/usr/include/linux/cpumask.h:121: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:121: error: `src1p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:121: error: `src2p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:121: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:125: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_or':
/usr/include/linux/cpumask.h:128: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:128: error: `src1p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:128: error: `src2p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:128: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:132: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_xor':
/usr/include/linux/cpumask.h:135: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:135: error: `src1p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:135: error: `src2p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:135: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:140: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_andnot':
/usr/include/linux/cpumask.h:143: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:143: error: `src1p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:143: error: `src2p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:143: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:147: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_complement':
/usr/include/linux/cpumask.h:150: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:150: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:150: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:154: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_equal':
/usr/include/linux/cpumask.h:157: error: `src1p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:157: error: `src2p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:157: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:161: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_intersects':
/usr/include/linux/cpumask.h:164: error: `src1p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:164: error: `src2p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:164: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:168: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_subset':
/usr/include/linux/cpumask.h:171: error: `src1p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:171: error: `src2p' undeclared (first use in this function)
/usr/include/linux/cpumask.h:171: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:175: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_empty':
/usr/include/linux/cpumask.h:177: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:177: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:181: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_full':
/usr/include/linux/cpumask.h:183: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:183: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:187: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_weight':
/usr/include/linux/cpumask.h:189: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:189: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:194: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_shift_right':
/usr/include/linux/cpumask.h:197: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:197: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:197: error: `n' undeclared (first use in this function)
/usr/include/linux/cpumask.h:197: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:202: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpus_shift_left':
/usr/include/linux/cpumask.h:205: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:205: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:205: error: `n' undeclared (first use in this function)
/usr/include/linux/cpumask.h:205: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:209: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__first_cpu':
/usr/include/linux/cpumask.h:211: error: syntax error before "int"
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:215: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__next_cpu':
/usr/include/linux/cpumask.h:217: error: syntax error before "int"
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:266: error: syntax error before '*' token
/usr/include/linux/cpumask.h: In function `__cpumask_scnprintf':
/usr/include/linux/cpumask.h:268: error: `buf' undeclared (first use in this function)
/usr/include/linux/cpumask.h:268: error: `len' undeclared (first use in this function)
/usr/include/linux/cpumask.h:268: error: `srcp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:268: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:274: error: syntax error before "cpumask_t"
/usr/include/linux/cpumask.h: In function `__cpumask_parse':
/usr/include/linux/cpumask.h:276: error: `buf' undeclared (first use in this function)
/usr/include/linux/cpumask.h:276: error: `len' undeclared (first use in this function)
/usr/include/linux/cpumask.h:276: error: `dstp' undeclared (first use in this function)
/usr/include/linux/cpumask.h:276: error: `nbits' undeclared (first use in this function)
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:344: error: syntax error before "cpu_possible_map"
/usr/include/linux/cpumask.h:345: error: syntax error before "cpu_online_map"
/usr/include/linux/cpumask.h:346: error: syntax error before "cpu_present_map"
In file included from /usr/include/asm/mmu.h:4,
from /usr/include/linux/sched.h:21,
from /usr/include/linux/module.h:9,
from hello.c:10:
/usr/include/asm-x86_64/mmu.h:15: error: syntax error before "rwlock_t"
/usr/include/asm-x86_64/mmu.h:18: error: syntax error before '}' token
In file included from /usr/include/linux/signal.h:4,
from /usr/include/linux/sched.h:25,
from /usr/include/linux/module.h:9,
from hello.c:10:
/usr/include/linux/list.h:715:2: warning: #warning "don't include kernel headers in userspace"
In file included from /usr/include/linux/sched.h:27,
from /usr/include/linux/module.h:9,
from hello.c:10:
/usr/include/linux/fs_struct.h:9: error: syntax error before "rwlock_t"
/usr/include/linux/fs_struct.h:13: error: syntax error before '}' token
In file included from /usr/include/linux/sched.h:29,
from /usr/include/linux/module.h:9,
from hello.c:10:
/usr/include/linux/completion.h:15: error: syntax error before "wait_queue_head_t"
/usr/include/linux/completion.h: In function `init_completion':
/usr/include/linux/completion.h:26: error: dereferencing pointer to incomplete type
/usr/include/linux/completion.h:27: error: dereferencing pointer to incomplete type
In file included from /usr/include/linux/sched.h:30,
from /usr/include/linux/module.h:9,
from hello.c:10:
/usr/include/linux/pid.h: At top level:
/usr/include/linux/pid.h:17: error: field `pid_chain' has incomplete type
/usr/include/linux/pid.h:19: error: field `pid_list' has incomplete type
In file included from /usr/include/linux/module.h:9,
from hello.c:10:
/usr/include/linux/sched.h:92: error: syntax error before "process_counts"
In file included from /usr/include/linux/sched.h:101,
from /usr/include/linux/module.h:9,
from hello.c:10:
/usr/include/linux/timer.h:11: error: field `entry' has incomplete type
In file included from /usr/include/asm/pda.h:4,
from /usr/include/asm-x86_64/current.h:7,
from /usr/include/asm/current.h:4,
from /usr/include/asm-x86_64/processor.h:18,
from /usr/include/asm/processor.h:4,
from /usr/include/linux/sched.h:103,
from /usr/include/linux/module.h:9,
from hello.c:10:
/usr/include/asm-x86_64/pda.h:26: error: `CONFIG_X86_L1_CACHE_SHIFT' undeclared here (not in a function)
/usr/include/asm-x86_64/pda.h:26: error: requested alignment is not a constant
In file included from /usr/include/asm/processor.h:4,
from /usr/include/linux/sched.h:103,
from /usr/include/linux/module.h:9,
from hello.c:10:
/usr/include/asm-x86_64/processor.h:190: error: syntax error before "u16"
/usr/include/asm-x86_64/processor.h:192: error: syntax error before "twd"
/usr/include/asm-x86_64/processor.h:193: error: syntax error before "fop"
/usr/include/asm-x86_64/processor.h:194: error: syntax error before "rip"
/usr/include/asm-x86_64/processor.h:195: error: syntax error before "rdp"
/usr/include/asm-x86_64/processor.h:196: error: syntax error before "mxcsr"
/usr/include/asm-x86_64/processor.h:197: error: syntax error before "mxcsr_mask"
/usr/include/asm-x86_64/processor.h:198: error: syntax error before "st_space"
/usr/include/asm-x86_64/processor.h:199: error: syntax error before "xmm_space"
/usr/include/asm-x86_64/processor.h:200: error: syntax error before "padding"
/usr/include/asm-x86_64/processor.h:201: error: syntax error before '}' token
/usr/include/asm-x86_64/processor.h:204: error: field `fxsave' has incomplete type
/usr/include/asm-x86_64/processor.h:208: error: syntax error before "u32"
/usr/include/asm-x86_64/processor.h:210: error: syntax error before "rsp1"
/usr/include/asm-x86_64/processor.h:211: error: syntax error before "rsp2"
/usr/include/asm-x86_64/processor.h:212: error: syntax error before "reserved2"
/usr/include/asm-x86_64/processor.h:213: error: syntax error before "ist"
/usr/include/asm-x86_64/processor.h:214: error: syntax error before "reserved3"
/usr/include/asm-x86_64/processor.h:215: error: syntax error before "reserved4"
/usr/include/asm-x86_64/processor.h:216: error: syntax error before "reserved5"
/usr/include/asm-x86_64/processor.h:217: error: syntax error before "io_bitmap_base"
/usr/include/asm-x86_64/processor.h:228: error: syntax error before '}' token
/usr/include/asm-x86_64/processor.h:228: error: `CONFIG_X86_L1_CACHE_SHIFT' undeclared here (not in a function)
/usr/include/asm-x86_64/processor.h:259: error: syntax error before "u64"
/usr/include/asm-x86_64/processor.h: In function `prefetchw':
/usr/include/asm-x86_64/processor.h:401: error: called object is not a function
hello.c: At top level:
/usr/include/asm-x86_64/mmu.h:17: error: storage size of `sem' isn't known
psullivan@linux:~>
---
The first problem I see is that you seem to be picking up your headers from "/usr/include".
You absolutely need to do the following:
1. Download and configure the kernel source (typically in "/usr/src/<<version>>",
but it could also be under your home directory or in a special project directory).
2. Download and install the kernel development tools.
On Suse, if you go into Yast2 and install gcc, kernel-sources and
kernel-docs, you should be covered.
3. Set up your environment to use the kernel tools and point to the kernel
source whenever you build your own kernel modules.
Strong suggestion: please consider buying these two books (worth their weight in gold):
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.