LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 02-23-2006, 02:17 AM   #1
pat_and_cami
LQ Newbie
 
Registered: Feb 2006
Posts: 16

Rep: Reputation: 0
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?

Program:

---
/* hello.c
*
* "Hello, world" - the kernel module version.
*/

/* The necessary header files */

/* Standard in kernel modules */
#include <linux/kernel.h> /* We're doing kernel work */
#include <linux/module.h> /* Specifically, a module */


/* Initialize the module */
int init_module()
{
printk("Hello World!!!!!!\n");

/* If we return a non zero value, it means that init_module failed and
* the kernel module can't be loaded */
return 0;
}


/* Cleanup - undid whatever init_module did */
void cleanup_module()
{
printk("Goodbye World!!!!!\n");
}
---

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:~>
---


Thanks,

Patrick//
 
Old 02-25-2006, 11:34 AM   #2
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 02-25-2006, 01:13 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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):

"Linux Kernel Development, 2nd Ed."; Robert Love
http://www.bookpool.com/sm/0672327201

"Writing Linux Device Drivers, 3rd Ed."; Borbett, Rubini, Kroah-Hartman
http://www.bookpool.com/sm/0596005903

In the meantime, these links might be of help:

http://lwn.net/Kernel/LDD3/
<= The complete "Linux Device Drivers, 3rd Ed" book online

ftp://ftp.ora.com/pub/examples/linux/drivers
<= All sample code ...
... including the shell scripts, makefile and source for "hello world"

'Hope that helps .. PSM

Last edited by paulsm4; 02-25-2006 at 01:20 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to compile and run a java program in linux !!!! jmax24 Programming 7 08-06-2010 03:56 AM
Visual Basic like program for Linux shortname Linux - Software 1 02-07-2005 08:12 PM
GIF gone in program when compile Java in Linux dwarf007 Programming 1 09-30-2004 11:15 PM
Compile linux program for windows Mor_Petrus Programming 3 04-08-2003 11:11 AM
Basic Unix Program for Linux Daniel Programming 10 07-05-2001 12:17 PM

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

All times are GMT -5. The time now is 11:56 PM.

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