Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Development & Programming > Programming Talk
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Programming Talk
This forum is for all programming questions.
The questions do not have to be directly related to Ubuntu and any programming language is allowed.

 
Thread Tools Display Modes
Old December 19th, 2007   #1
thejdev
Spilled the Beans
 
Join Date: Nov 2007
Beans: 14
Unable to compile the simplest of kernel modules

I'm running x86_64 gutsy on an AMD 64 bit dual core machine (1 GB RAM,200 GB SATA HDD) but I dont have an internet connection . I've installed the build-essential packages for gcc,g++ and libc6-dev that come along with the live cd and have installed the kernel headers package for kernel 2.6.22-14 that comes as a .deb package on the ubuntu website .
I tried to compile a simple hello world kernel module (see below) :

PHP Code:
//hello.c in root folder

#include <linux/kernel.h>
#include <linux/module.h>

#if CONFIG_MODVERSIONS == 1
#define MODVERSIONS
#include <linux/modversions.h>
#endif

int init_module()
{
     
printk("\n\nHello world \n\n");
     return(
0);
}

void cleanup_module()
{
printk("\n\nBye\n\n");}


root@Babu:/# gcc -I /usr/src/linux-headers-2.6.22-14/include -Wall -D__KERNEL__ -DMODULE -c hello.c
In file included from /usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:11,
                 
from hello.c:1:
/
usr/src/linux-headers-2.6.22-14/include/linux/linkage.h:4:25errorasm/linkage.hNo such file or directory
In file included from 
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:15,
                 
from hello.c:1:
/
usr/src/linux-headers-2.6.22-14/include/linux/bitops.h:9:24errorasm/bitops.hNo such file or directory
In file included from 
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:15,
                 
from hello.c:1:
/
usr/src/linux-headers-2.6.22-14/include/linux/bitops.hIn function ‘get_bitmask_order’:
/
usr/src/linux-headers-2.6.22-14/include/linux/bitops.h:15warningimplicit declaration of function ‘fls’
/usr/src/linux-headers-2.6.22-14/include/linux/bitops.hIn function ‘hweight_long’:
/
usr/src/linux-headers-2.6.22-14/include/linux/bitops.h:31warningimplicit declaration of function ‘hweight32’
/usr/src/linux-headers-2.6.22-14/include/linux/bitops.h:31warningimplicit declaration of function ‘hweight64’
/usr/src/linux-headers-2.6.22-14/include/linux/bitops.hIn function ‘fls_long’:
/
usr/src/linux-headers-2.6.22-14/include/linux/bitops.h:58warningimplicit declaration of function ‘fls64’
In file included from hello
.c:1:
/
usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:18:21errorasm/bug.hNo such file or directory
In file included from 
/usr/src/linux-headers-2.6.22-14/include/linux/preempt.h:9,
                 
from /usr/src/linux-headers-2.6.22-14/include/linux/spinlock.h:49,
                 
from /usr/src/linux-headers-2.6.22-14/include/linux/module.h:9,
                 
from hello.c:2:
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:21:29errorasm/thread_info.hNo such file or directory
In file included from 
/usr/src/linux-headers-2.6.22-14/include/linux/preempt.h:9,
                 
from /usr/src/linux-headers-2.6.22-14/include/linux/spinlock.h:49,
                 
from /usr/src/linux-headers-2.6.22-14/include/linux/module.h:9,
                 
from hello.c:2:
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.hAt top level:
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:30warning‘struct thread_info’ declared inside parameter list
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:30warningits scope is only this definition or declarationwhich is probably not what you want
/usr/src/linux-headers-2.6.22-14/include/linux/thread_info.hIn function ‘set_ti_thread_flag’:
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:32warningimplicit declaration of function ‘set_bit’
/usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:32errordereferencing pointer to incomplete type
/usr/src/linux-headers-2.6.22-14/include/linux/thread_info.hAt top level:
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:35warning‘struct thread_info’ declared inside parameter list
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.hIn function ‘clear_ti_thread_flag’:
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:37warningimplicit declaration of function ‘clear_bit’
/usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:37errordereferencing pointer to incomplete type
/usr/src/linux-headers-2.6.22-14/include/linux/thread_info.hAt top level:
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:40warning‘struct thread_info’ declared inside parameter list
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.hIn function ‘test_and_set_ti_thread_flag’:
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:42warningimplicit declaration of function ‘test_and_set_bit’
/usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:42errordereferencing pointer to incomplete type
/usr/src/linux-headers-2.6.22-14/include/linux/thread_info.hAt top level:
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:45warning‘struct thread_info’ declared inside parameter list
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.hIn function ‘test_and_clear_ti_thread_flag’:
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:47warningimplicit declaration of function ‘test_and_clear_bit’
/usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:47errordereferencing pointer to incomplete type
/usr/src/linux-headers-2.6.22-14/include/linux/thread_info.hAt top level:
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:50warning‘struct thread_info’ declared inside parameter list
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.hIn function ‘test_ti_thread_flag’:
/
usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:52warningimplicit declaration of function ‘test_bit’
/usr/src/linux-headers-2.6.22-14/include/linux/thread_info.h:52errordereferencing pointer to incomplete type
In file included from 
/usr/src/linux-headers-2.6.22-14/include/linux/module.h:9,
                 
from hello.c:2:
/
usr/src/linux-headers-2.6.22-14/include/linux/spinlock.h:57:24errorasm/system.hNo such file or directory
/usr/src/linux-headers-2.6.22-14/include/linux/spinlock.h:326:24errorasm/atomic.hNo such file or directory
In file included from 
/usr/src/linux-headers-2.6.22-14/include/linux/module.h:9,
                 
from hello.c:2:
/
usr/src/linux-headers-2.6.22-14/include/linux/spinlock.hAt top level:
/
usr/src/linux-headers-2.6.22-14/include/linux/spinlock.h:332errorexpected ‘)’ before ‘*’ token
In file included from 
/usr/src/linux-headers-2.6.22-14/include/linux/list.h:8,
                 
from /usr/src/linux-headers-2.6.22-14/include/linux/module.h:10,
                 
from hello.c:2:
/
usr/src/linux-headers-2.6.22-14/include/linux/prefetch.h:14:27errorasm/processor.hNo such file or directory
/usr/src/linux-headers-2.6.22-14/include/linux/prefetch.h:15:23errorasm/cache.hNo such file or directory
In file included from 
/usr/src/linux-headers-2.6.22-14/include/linux/module.h:10,
                 
from hello.c:2:
/
usr/src/linux-headers-2.6.22-14/include/linux/list.hIn function ‘__list_add_rcu’:
/
usr/src/linux-headers-2.6.22-14/include/linux/list.h:100warningimplicit declaration of function ‘smp_wmb’
In file included from 
/usr/src/linux-headers-2.6.22-14/include/linux/time.h:7,
                 
from /usr/src/linux-headers-2.6.22-14/include/linux/stat.h:60,
                 
from /usr/src/linux-headers-2.6.22-14/include/linux/module.h:11,
                 
from hello.c:2:
/
usr/src/linux-headers-2.6.22-14/include/linux/seqlock.hIn function ‘read_seqbegin’:
/
usr/src/linux-headers-2.6.22-14/include/linux/seqlock.h:89warningimplicit declaration of function ‘smp_rmb’
In file included from 
/usr/src/linux-headers-2.6.22-14/include/linux/kobject.h:25,
                 
from /usr/src/linux-headers-2.6.22-14/include/linux/module.h:17,
                 
from hello.c:2:
/
usr/src/linux-headers-2.6.22-14/include/linux/kref.hAt top level:
/
usr/src/linux-headers-2.6.22-14/include/linux/kref.h:24errorexpected specifier-qualifier-list before ‘atomic_t’
In file included from 
/usr/src/linux-headers-2.6.22-14/include/linux/kobject.h:27,
                 
from /usr/src/linux-headers-2.6.22-14/include/linux/module.h:17,
                 
from hello.c:2:
/
usr/src/linux-headers-2.6.22-14/include/linux/wait.h:26:25errorasm/current.hNo such file or directory
In file included from hello
.c:2:
/
usr/src/linux-headers-2.6.22-14/include/linux/module.h:19:23errorasm/local.hNo such file or directory
/usr/src/linux-headers-2.6.22-14/include/linux/module.h:21:24errorasm/module.hNo such file or directory 
Whoa someone's unhappy !

I'm not allowed an internet connection on my comp as I live in a hostel , so could someone please direct me how to get the build essential package for kernel headers through windows . I've been trying for over a week now , unsuccessfully
thejdev is offline   Reply With Quote
Old December 19th, 2007   #2
moma
Quad Shot of Ubuntu
 
moma's Avatar
 
Join Date: Jan 2006
Location: Grønland,Oslo
Beans: 484
Re: Unable to compile the simplest of kernel modules

Hello,

Take a look at this module example.
http://ubuntuforums.org/showthread.p...57#post3486457

Note that "/lib/modules/$(uname -r)/build" is normally a symbolic link to /usr/src/linux-headers....

$ ls -l /lib/modules/$(uname -r)/build
lrwxrwxrwx 1 root root 40 2007-10-10 10:47 /lib/modules/2.6.22-14-generic/build -> /usr/src/linux-headers-2.6.22-14-generic

Study also the guides under "Driver and module programming" of this guide.
---- ---- ---- ---- ---- ---- ---- ----

Downloading packages for your offline system.

As you already know, you will need at least these components. (The examples are taken from my 32 bits Ubuntu)
$ apt-cache search linux-headers-$(uname -r)
linux-headers-2.6.22-14-generic - Linux kernel headers for version 2.6.22 on x86/x86_64

$ apt-cache search build-essential
build-essential - informational list of build-essential packages
---

Browse to http://packages.ubuntu.com/ and search for the package names.

Download the (.deb) packages for your system (is it a 64-bits Gutsy?)
Important: Take also all depending packages ! Eg. the "build-essential" pack has these dependencies.... , Ok?

Use the "dpkg -i" command to install the packages on your offline system.
$ sudo dpkg -i *deb

Maybe some of the packages lay on the installation CD too. I do not know.

Merry Christmas
$ xsnow
__________________
// moma
http://www.futuredesktop.org

Last edited by moma; December 19th, 2007 at 09:19 AM..
moma is offline   Reply With Quote
Old December 19th, 2007   #3
moma
Quad Shot of Ubuntu
 
moma's Avatar
 
Join Date: Jan 2006
Location: Grønland,Oslo
Beans: 484
Re: Unable to compile the simplest of kernel modules

<duplicate posting. deleted>
__________________
// moma
http://www.futuredesktop.org

Last edited by moma; December 19th, 2007 at 09:19 AM..
moma is offline   Reply With Quote
Old December 19th, 2007   #4
thejdev
Spilled the Beans
 
Join Date: Nov 2007
Beans: 14
Re: Unable to compile the simplest of kernel modules

So its not possible to compile a kernel module directly using the gcc command ..... I never knew .... Thanks a lot ...
thejdev is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:07 AM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. bilberry