LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 12-17-2005, 04:11 PM   #1
NNP
Member
 
Registered: Nov 2004
Distribution: Debian/Ubuntu
Posts: 156

Rep: Reputation: 30
Compiling kernel modules


Im interested in coding some kernel modules etc so i went to the kernel programming guide on the linux documentation project. Im using debian sarge with a 2.4.27 kernel so i copied the hello world code straight out of the guide to make sure everything would work before i really got stuck in....it didnt :P

Here is the code:

Code:
/*  hello-1.c - The simplest kernel module.
 */
#include <linux/module.h>  /* Needed by all modules */
#include <linux/kernel.h>  /* Needed for KERN_ALERT */


int init_module(void)
{
   printk("<1>Hello world 1.\n");
	
   // A non 0 return means init_module failed; module can't be loaded.
   return 0;
}


void cleanup_module(void)
{
  printk(KERN_ALERT "Goodbye world 1.\n");
}
and the makefile

Code:
TARGET  := hello-1
WARN    := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
CFLAGS  := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC      := gcc
	
${TARGET}.o: ${TARGET}.c

.PHONY: clean

clean:
    rm -rf ${TARGET}.o
The result of running make was a bucket load of errors which i wont copy and paste in here cause there we're over a hundred. Basically they consisted of stuff like "/usr/include/linux/stat.h:67: syntax error before etc etc"
It claimed syntax errors in many files including percpu.h, ipc.h, sched.h

At the start of all error groups though was "error in file included from /usr/include/linux/module.h:13 from hello-1.c:3" with the line number in module.h changing depending on the file module.h was trying to #include

Has anyone any idea whats going on here? I fail to believe those files included my module.h have all the errors gcc is claiming.

Thanks,
NNP
 
Old 12-17-2005, 04:43 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Please cut and paste:

1. The actual "gcc" output from the first .o file (probably you're *only* .c/.o) that fails

2. The first couple of lines (2, 5, 10: whatever you think makes sense)

The Gcc compile line and start of the error output will definitely help a lot.

TIA .. PSM

PS:
It wouldn't hurt to get ahold of "Linux Device Drivers, 3rd Edition", O'Reilly and/or pull the sample source files from their web site.

Last edited by paulsm4; 12-17-2005 at 04:44 PM.
 
Old 12-18-2005, 08:11 AM   #3
NNP
Member
 
Registered: Nov 2004
Distribution: Debian/Ubuntu
Posts: 156

Original Poster
Rep: Reputation: 30
Here you go...

Code:
gcc -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/`uname -r`/build/include   -c -o hello-1.o hello-1.c
In file included from /usr/include/asm/system.h:5,
                 from /usr/include/asm/processor.h:18,
                 from /usr/include/asm/thread_info.h:13,
                 from /usr/include/linux/thread_info.h:21,
                 from /usr/include/linux/spinlock.h:19,
                 from /usr/include/linux/capability.h:45,
                 from /usr/include/linux/sched.h:7,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/kernel.h:72: error: syntax error before 'size_t'
/usr/include/linux/kernel.h:74: error: syntax error before 'size_t'
In file included from /usr/include/asm/thread_info.h:13,
                 from /usr/include/linux/thread_info.h:21,
                 from /usr/include/linux/spinlock.h:19,
                 from /usr/include/linux/capability.h:45,
                 from /usr/include/linux/sched.h:7,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/asm/processor.h:86: error: array type has incomplete element type
In file included from /usr/include/linux/timex.h:186,
                 from /usr/include/linux/sched.h:11,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/time.h:14: error: syntax error before 'time_t'
/usr/include/linux/time.h:16: error: syntax error before '}' token
/usr/include/linux/time.h:20: error: syntax error before 'time_t'
In file included from /usr/include/linux/timex.h:186,
                 from /usr/include/linux/sched.h:11,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/time.h: In function 'timespec_to_jiffies':
/usr/include/linux/time.h:198: error: dereferencing pointer to incomplete type
/usr/include/linux/time.h:199: error: dereferencing pointer to incomplete type
/usr/include/linux/time.h: In function 'jiffies_to_timespec':
/usr/include/linux/time.h:219: error: dereferencing pointer to incomplete type
/usr/include/linux/time.h:219: error: dereferencing pointer to incomplete type
/usr/include/linux/time.h: In function 'timeval_to_jiffies':
/usr/include/linux/time.h:237: error: dereferencing pointer to incomplete type
/usr/include/linux/time.h:238: error: dereferencing pointer to incomplete type
/usr/include/linux/time.h: In function 'jiffies_to_timeval':
/usr/include/linux/time.h:257: error: dereferencing pointer to incomplete type
/usr/include/linux/time.h:257: error: dereferencing pointer to incomplete type
/usr/include/linux/time.h:258: error: dereferencing pointer to incomplete type
/usr/include/linux/time.h: In function 'timespec_equal':
/usr/include/linux/time.h:263: error: dereferencing pointer to incomplete type
/usr/include/linux/time.h:263: error: dereferencing pointer to incomplete type
/usr/include/linux/time.h:263: error: dereferencing pointer to incomplete type
/usr/include/linux/time.h:263: error: dereferencing pointer to incomplete type
/usr/include/linux/time.h: In function 'get_seconds':
/usr/include/linux/time.h:305: error: invalid use of undefined type 'struct timespec'
/usr/include/linux/time.h: At top level:
/usr/include/linux/time.h:329: error: syntax error before 'time_t'
/usr/include/linux/time.h: In function 'set_normalized_timespec':
/usr/include/linux/time.h:331: error: 'nsec' undeclared (first use in this function)
/usr/include/linux/time.h:331: error: (Each undeclared identifier is reported only once
/usr/include/linux/time.h:331: error: for each function it appears in.)
/usr/include/linux/time.h:333: error: 'sec' undeclared (first use in this function)
/usr/include/linux/time.h:339: error: 'ts' undeclared (first use in this function)
/usr/include/linux/time.h: At top level:
/usr/include/linux/time.h:359: error: field 'it_interval' has incomplete type
/usr/include/linux/time.h:360: error: field 'it_value' has incomplete type
/usr/include/linux/time.h:364: error: field 'it_interval' has incomplete type
/usr/include/linux/time.h:365: error: field 'it_value' has incomplete type
In file included from /usr/include/linux/sched.h:11,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/timex.h:203: error: field 'time' has incomplete type
In file included from /usr/include/linux/string.h:23,
                 from /usr/include/linux/bitmap.h:11,
                 from /usr/include/linux/cpumask.h:8,
                 from /usr/include/linux/sched.h:15,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/asm/string.h:41: error: syntax error before 'size_t'
/usr/include/asm/string.h: In function 'strncpy':
/usr/include/asm/string.h:55: error: 'src' undeclared (first use in this function)
/usr/include/asm/string.h:55: error: 'dest' undeclared (first use in this function)
/usr/include/asm/string.h:55: error: 'count' undeclared (first use in this function)
/usr/include/asm/string.h: At top level:
/usr/include/asm/string.h:77: error: syntax error before 'size_t'
/usr/include/asm/string.h: In function 'strncat':
/usr/include/asm/string.h:94: error: 'src' undeclared (first use in this function)
/usr/include/asm/string.h:94: error: 'dest' undeclared (first use in this function)
/usr/include/asm/string.h:94: error: 'count' undeclared (first use in this function)
/usr/include/asm/string.h: At top level:
/usr/include/asm/string.h:121: error: syntax error before 'size_t'
/usr/include/asm/string.h: In function 'strncmp':
/usr/include/asm/string.h:139: error: 'cs' undeclared (first use in this function)
/usr/include/asm/string.h:139: error: 'ct' undeclared (first use in this function)
/usr/include/asm/string.h:139: error: 'count' undeclared (first use in this function)
/usr/include/asm/string.h: At top level:
/usr/include/asm/string.h:180: error: syntax error before 'strlen'
/usr/include/asm/string.h:193: error: syntax error before 'size_t'
/usr/include/asm/string.h: In function '__memcpy':
/usr/include/asm/string.h:206: error: 'n' undeclared (first use in this function)
/usr/include/asm/string.h:206: error: 'to' undeclared (first use in this function)
/usr/include/asm/string.h:206: error: 'from' undeclared (first use in this function)
/usr/include/asm/string.h: At top level:
/usr/include/asm/string.h:215: error: syntax error before 'size_t'
/usr/include/asm/string.h: In function '__constant_memcpy':
/usr/include/asm/string.h:217: error: 'n' undeclared (first use in this function)
/usr/include/asm/string.h:218: error: 'to' undeclared (first use in this function)
/usr/include/asm/string.h:218: error: 'from' undeclared (first use in this function)
/usr/include/asm/string.h: At top level:
/usr/include/asm/string.h:299: error: syntax error before 'size_t'
/usr/include/asm/string.h: In function 'memmove':
/usr/include/asm/string.h:302: error: 'dest' undeclared (first use in this function)
/usr/include/asm/string.h:302: error: 'src' undeclared (first use in this function)
/usr/include/asm/string.h:307: error: 'n' undeclared (first use in this function)
/usr/include/asm/string.h: At top level:
/usr/include/asm/string.h:326: error: syntax error before 'size_t'
/usr/include/asm/string.h: In function 'memchr':
/usr/include/asm/string.h:330: error: 'count' undeclared (first use in this function)
/usr/include/asm/string.h:338: error: 'c' undeclared (first use in this function)
/usr/include/asm/string.h:338: error: 'cs' undeclared (first use in this function)
/usr/include/asm/string.h: At top level:
/usr/include/asm/string.h:342: error: syntax error before 'size_t'
/usr/include/asm/string.h: In function '__memset_generic':
/usr/include/asm/string.h:349: error: 'c' undeclared (first use in this function)
/usr/include/asm/string.h:349: error: 's' undeclared (first use in this function)
/usr/include/asm/string.h:349: error: 'count' undeclared (first use in this function)
/usr/include/asm/string.h: At top level:
/usr/include/asm/string.h:362: error: syntax error before 'size_t'
/usr/include/asm/string.h: In function '__constant_c_memset':
/usr/include/asm/string.h:375: error: 'c' undeclared (first use in this function)
/usr/include/asm/string.h:375: error: 'count' undeclared (first use in this function)
/usr/include/asm/string.h:375: error: 's' undeclared (first use in this function)
/usr/include/asm/string.h: At top level:
/usr/include/asm/string.h:382: error: syntax error before 'strnlen'
/usr/include/asm/string.h:382: error: syntax error before 'size_t'
/usr/include/asm/string.h: In function 'strnlen':
/usr/include/asm/string.h:397: error: 's' undeclared (first use in this function)
/usr/include/asm/string.h:397: error: 'count' undeclared (first use in this function)
/usr/include/asm/string.h: At top level:
/usr/include/asm/string.h:410: error: syntax error before 'size_t'
/usr/include/asm/string.h: In function '__constant_c_and_count_memset':
/usr/include/asm/string.h:412: error: 'count' undeclared (first use in this function)
/usr/include/asm/string.h:414: error: 's' undeclared (first use in this function)
/usr/include/asm/string.h:416: error: 'pattern' undeclared (first use in this function)
/usr/include/asm/string.h: At top level:
/usr/include/asm/string.h:469: error: syntax error before 'size_t'
/usr/include/asm/string.h: In function 'memscan':
/usr/include/asm/string.h:471: error: 'size' undeclared (first use in this function)
/usr/include/asm/string.h:472: error: 'addr' undeclared (first use in this function)
/usr/include/asm/string.h:478: error: 'c' undeclared (first use in this function)
/usr/include/asm/string.h:473: error: invalid lvalue in asm output 0
/usr/include/asm/string.h:473: error: invalid lvalue in asm output 1
In file included from /usr/include/linux/bitmap.h:11,
                 from /usr/include/linux/cpumask.h:8,
                 from /usr/include/linux/sched.h:15,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/string.h: At top level:
/usr/include/linux/string.h:32: error: syntax error before 'strlcpy'
/usr/include/linux/string.h:32: error: syntax error before 'size_t'
/usr/include/linux/string.h:41: error: syntax error before 'strlcat'
In file included from /usr/include/linux/sem.h:4,
                 from /usr/include/linux/sched.h:24,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/ipc.h:61: error: syntax error before 'key_t'
/usr/include/linux/ipc.h:63: error: syntax error before 'gid'
/usr/include/linux/ipc.h:64: error: syntax error before 'cuid'
/usr/include/linux/ipc.h:65: error: syntax error before 'cgid'
/usr/include/linux/ipc.h:66: error: syntax error before 'mode'
/usr/include/linux/ipc.h:69: error: syntax error before '}' token
In file included from /usr/include/linux/sched.h:24,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/sem.h:90: error: field 'sem_perm' has incomplete type
/usr/include/linux/sem.h:91: error: syntax error before 'time_t'
/usr/include/linux/sem.h:98: error: syntax error before '}' token
/usr/include/linux/sem.h:137: error: syntax error before 'key'
In file included from /usr/include/linux/signal.h:6,
                 from /usr/include/linux/sched.h:25,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/asm/signal.h:176: error: syntax error before 'size_t'
In file included from /usr/include/asm/siginfo.h:4,
                 from /usr/include/linux/signal.h:7,
                 from /usr/include/linux/sched.h:25,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/asm-generic/siginfo.h:45: error: syntax error before 'pid_t'
/usr/include/asm-generic/siginfo.h:51: error: syntax error before 'timer_t'
/usr/include/asm-generic/siginfo.h:53: error: 'uid_t' undeclared here (not in a function)
/usr/include/asm-generic/siginfo.h:56: error: syntax error before '}' token
/usr/include/asm-generic/siginfo.h:60: error: syntax error before 'pid_t'
/usr/include/asm-generic/siginfo.h:63: error: syntax error before '}' token
/usr/include/asm-generic/siginfo.h:67: error: syntax error before 'pid_t'
/usr/include/asm-generic/siginfo.h:70: error: syntax error before '_utime'
/usr/include/asm-generic/siginfo.h:71: error: syntax error before '_stime'
/usr/include/asm-generic/siginfo.h:87: error: syntax error before '}' token
/usr/include/asm-generic/siginfo.h:88: error: syntax error before '}' token
/usr/include/asm-generic/siginfo.h: In function 'copy_siginfo':
/usr/include/asm-generic/siginfo.h:274: error: dereferencing pointer to incomplete type
/usr/include/asm-generic/siginfo.h:275: error: dereferencing pointer to incomplete type
/usr/include/asm-generic/siginfo.h:275: error: dereferencing pointer to incomplete type
/usr/include/asm-generic/siginfo.h:275: error: dereferencing pointer to incomplete type
/usr/include/asm-generic/siginfo.h:278: error: dereferencing pointer to incomplete type
/usr/include/asm-generic/siginfo.h:278: error: dereferencing pointer to incomplete type
/usr/include/asm-generic/siginfo.h:278: error: dereferencing pointer to incomplete type
In file included from /usr/include/linux/sched.h:25,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/signal.h: At top level:
/usr/include/linux/signal.h:18: error: syntax error before 'siginfo_t'
/usr/include/linux/signal.h:215: error: syntax error before '*' token
In file included from /usr/include/linux/gfp.h:4,
                 from /usr/include/linux/slab.h:15,
                 from /usr/include/linux/percpu.h:4,
                 from /usr/include/linux/sched.h:31,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/mmzone.h:286: error: syntax error before 'size_t'
In file included from /usr/include/linux/percpu.h:4,
                 from /usr/include/linux/sched.h:31,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/slab.h:58: error: syntax error before 'int'
/usr/include/linux/slab.h:59: error: syntax error before 'size_t'
/usr/include/linux/slab.h:60: error: 'kmem_cache_create' declared as function returning a function
/usr/include/linux/slab.h:61: error: syntax error before 'void'
/usr/include/linux/slab.h:70: error: syntax error before 'size_t'
/usr/include/linux/slab.h:73: error: syntax error before '}' token
/usr/include/linux/slab.h:74: error: array type has incomplete element type
/usr/include/linux/slab.h:75: error: syntax error before 'int'
/usr/include/linux/slab.h:77: error: syntax error before 'size'
/usr/include/linux/slab.h: In function 'kmalloc':
/usr/include/linux/slab.h:79: error: 'size' undeclared (first use in this function)
In file included from /usr/include/linux/percpu.h:4,
                 from /usr/include/linux/sched.h:31,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/slab.h:93: error: 'flags' undeclared (first use in this function)
In file included from /usr/include/linux/sched.h:31,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/percpu.h: At top level:
/usr/include/linux/percpu.h:44: error: syntax error before 'size'
/usr/include/linux/percpu.h: In function '__alloc_percpu':
/usr/include/linux/percpu.h:46: error: 'size' undeclared (first use in this function)
In file included from /usr/include/linux/sched.h:101,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/resource.h: At top level:
/usr/include/linux/resource.h:22: error: field 'ru_utime' has incomplete type
/usr/include/linux/resource.h:23: error: field 'ru_stime' has incomplete type
In file included from /usr/include/linux/sched.h:183,
                 from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/aio.h:64: error: syntax error before 'loff_t'
/usr/include/linux/aio.h:67: error: syntax error before '}' token
/usr/include/linux/aio.h:143: error: syntax error before 'wait_on_sync_kiocb'
/usr/include/linux/aio.h: In function 'list_kiocb':
/usr/include/linux/aio.h:166: error: dereferencing pointer to incomplete type
/usr/include/linux/aio.h:166: error: 'size_t' undeclared (first use in this function)
/usr/include/linux/aio.h:166: error: dereferencing pointer to incomplete type
In file included from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/sched.h: At top level:
/usr/include/linux/sched.h:299: error: syntax error before 'uid_t'
/usr/include/linux/sched.h:315: error: syntax error before 'clockid_t'
/usr/include/linux/sched.h:327: error: syntax error before '}' token
/usr/include/linux/sched.h:368: error: syntax error before 'pid_t'
/usr/include/linux/sched.h:370: error: syntax error before 'tty_old_pgrp'
/usr/include/linux/sched.h:371: error: syntax error before 'session'
/usr/include/linux/sched.h:372: error: syntax error before 'tgid'
/usr/include/linux/sched.h:405: error: syntax error before 'uid'
/usr/include/linux/sched.h:406: error: syntax error before 'gid'
/usr/include/linux/sched.h:408: error: syntax error before 'groups'
/usr/include/linux/sched.h:410: error: syntax error before ':' token
/usr/include/linux/sched.h:437: error: syntax error before 'sas_ss_size'
/usr/include/linux/sched.h:466: error: syntax error before '*' token
/usr/include/linux/sched.h:467: error: syntax error before '}' token
/usr/include/linux/sched.h:469: error: syntax error before 'process_group'
/usr/include/linux/sched.h: In function 'process_group':
/usr/include/linux/sched.h:471: error: dereferencing pointer to incomplete type
/usr/include/linux/sched.h: At top level:
/usr/include/linux/sched.h:560: error: syntax error before 'session'
/usr/include/linux/sched.h:561: error: syntax error before 'session'
In file included from /usr/include/linux/module.h:10,
                 from hello-1.c:3:
/usr/include/linux/sched.h:580: error: syntax error before 'pid'
/usr/include/linux/sched.h:588: error: syntax error before 'siginfo_t'
/usr/include/linux/sched.h:590: error: syntax error before 'siginfo_t'
/usr/include/linux/sched.h: In function 'dequeue_signal_lock':
/usr/include/linux/sched.h:595: error: 'tsk' undeclared (first use in this function)
/usr/include/linux/sched.h:596: error: 'mask' undeclared (first use in this function)
/usr/include/linux/sched.h:596: error: 'info' undeclared (first use in this function)
/usr/include/linux/sched.h: At top level:
/usr/include/linux/sched.h:609: error: syntax error before 'pid_t'
/usr/include/linux/sched.h:610: error: syntax error before 'pid_t'
/usr/include/linux/sched.h:611: error: syntax error before 'pid_t'
/usr/include/linux/sched.h:612: error: syntax error before 'pid_t'
/usr/include/linux/sched.h:619: error: syntax error before 'int'
/usr/include/linux/sched.h:620: error: syntax error before 'int'
/usr/include/linux/sched.h:621: error: syntax error before 'int'
/usr/include/linux/sched.h:627: error: syntax error before '*' token
/usr/include/linux/sched.h: In function 'on_sig_stack':
/usr/include/linux/sched.h:638: error: dereferencing pointer to incomplete type
/usr/include/linux/sched.h:638: error: dereferencing pointer to incomplete type
/usr/include/linux/sched.h: In function 'sas_ss_flags':
/usr/include/linux/sched.h:643: error: dereferencing pointer to incomplete type
/usr/include/linux/sched.h: In function 'capable':
/usr/include/linux/sched.h:654: error: dereferencing pointer to incomplete type
/usr/include/linux/sched.h:655: error: dereferencing pointer to incomplete type
/usr/include/linux/sched.h: In function 'thread_group_empty':
/usr/include/linux/sched.h:749: error: dereferencing pointer to incomplete type
/usr/include/linux/sched.h: In function 'task_lock':
/usr/include/linux/sched.h:766: error: dereferencing pointer to incomplete type
/usr/include/linux/sched.h: In function 'task_unlock':
/usr/include/linux/sched.h:771: error: dereferencing pointer to incomplete type
/usr/include/linux/sched.h: In function 'get_task_mm':
/usr/include/linux/sched.h:785: error: dereferencing pointer to incomplete type
/usr/include/linux/sched.h: In function 'set_tsk_thread_flag':
/usr/include/linux/sched.h:799: error: dereferencing pointer to incomplete type
/usr/include/linux/sched.h: In function 'clear_tsk_thread_flag':
/usr/include/linux/sched.h:804: error: dereferencing pointer to incomplete type
/usr/include/linux/sched.h: In function 'test_and_set_tsk_thread_flag':
/usr/include/linux/sched.h:809: error: dereferencing pointer to incomplete type
/usr/include/linux/sched.h: In function 'test_and_clear_tsk_thread_flag':
/usr/include/linux/sched.h:814: error: dereferencing pointer to incomplete type
/usr/include/linux/sched.h: In function 'test_tsk_thread_flag':
/usr/include/linux/sched.h:819: error: dereferencing pointer to incomplete type
In file included from /usr/include/linux/module.h:13,
                 from hello-1.c:3:
/usr/include/linux/stat.h: At top level:
/usr/include/linux/stat.h:61: error: syntax error before 'dev_t'
/usr/include/linux/stat.h:62: error: conflicting types for 'mode'
/usr/include/linux/ipc.h:66: error: previous declaration of 'mode' was here
/usr/include/linux/stat.h:63: error: syntax error before 'nlink'
/usr/include/linux/stat.h:64: error: syntax error before 'uid'
/usr/include/linux/stat.h:65: error: syntax error before 'gid'
/usr/include/linux/stat.h:66: error: syntax error before 'rdev'
/usr/include/linux/stat.h:67: error: syntax error before 'size'
/usr/include/linux/stat.h:73: error: syntax error before '}' token
make: *** [hello-1.o] Error 1
nnp@debian:~/my_programs/c/linux/modules$
 
Old 12-18-2005, 12:29 PM   #4
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Something fundamental is wrong...

As you guessed, something very fundamental is wrong. This link doesn't have your exact problem, but good advice:

http://lists.debian.org/debian-user/.../msg03247.html

You might even want to consider re-downloading the kernel source. Be *sure* to run "make menuconfig" (or an equivalent).

Please consider the O'Reilly Device Drivers book (2nd Ed for Linux 2.4; 3rd Ed for Linux 2.6) and consider trying the accompanying examples.

'Hope that helps .. PSM
 
Old 12-18-2005, 02:08 PM   #5
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Sample output:

Oh yes - here's what happens when I try to install and build your module and your Makefile on my SuSE 8.2/Linux 2.4.20 system:
less hello.c =>
Code:
/*
 * hello-1.c - The simplest kernel module.
 */
#include <linux/module.h>  /* Needed by all modules */
#include <linux/kernel.h>  /* Needed for KERN_ALERT */


int init_module(void)
{
   printk("<1>Hello world 1.\n");

   // A non 0 return means init_module failed; module can't be loaded.
   return 0;
}


void cleanup_module(void)
{
  printk(KERN_ALERT "Goodbye world 1.\n");
}
less Makefile =>
Code:
TARGET  := hello
WARN    := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
CFLAGS  := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC      := gcc

${TARGET}.o: ${TARGET}.c

.PHONY: clean

clean:
        rm -rf ${TARGET}.o
make =>
Code:
gcc -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/`uname -r`/build/include   -c -o hello.o hello.c
hello.c:9: warning: no previous prototype for `init_module'
hello.c:18: warning: no previous prototype for `cleanup_module'
/lib/modules/2.4.20-4GB/build/include/linux/prefetch.h: In function `prefetch':
/lib/modules/2.4.20-4GB/build/include/linux/prefetch.h:43: warning: unused parameter `x'
/lib/modules/2.4.20-4GB/build/include/linux/prefetch.h: In function `prefetchw':
/lib/modules/2.4.20-4GB/build/include/linux/prefetch.h:48: warning: unused parameter `x'
insmod ./hello =>
Code:
Warning: loading ./hello.o will taint the kernel: no license
  See http://www.tux.org/lkml/#eHello world 1.
xport-tainted for information about tainted modules
Module hello loaded, with warnings
dmesg | tail =>
Code:
Hello world 1.
Again, I think (per the link above) that something's wrong with your basic kernel source configuration.
 
  


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
compiling kernel modules axr0284 Programming 2 11-26-2005 03:08 PM
Modules in Kernel Compiling SlackwareInAZ Slackware 1 07-29-2005 05:10 AM
need some help in Compiling Kernel modules bharat83 Suse/Novell 1 01-07-2005 07:21 AM
Compiling Modules for 2.6.6 kernel! Bigg Mike Linux - Newbie 9 06-09-2004 09:04 PM
Compiling kernel modules? jrjarrett Linux - Software 0 09-09-2003 10:24 AM


All times are GMT -5. The time now is 08:33 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration