LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-06-2004, 07:42 PM   #1
mathman0
LQ Newbie
 
Registered: Oct 2004
Distribution: Fedor Core 2
Posts: 15

Rep: Reputation: 0
compiling a module with gcc


writing a simple module trying to learn about writing device drivers...but i cant seem to get my code to compile properly
hello_module.c:
Code:
#include <linux/module.h>
                                                                             
#if defined(CONFIG_SMP)
#define __SMP__
#endif
                                                                             
#if defined(CONFIG_MODVERSIONS)
#define MODVERSIONS
#include <linux/modversions.h>
#endif
                                                                             
#include <linux/kernel.h>
                                                                             
int init_module(void)
{
        printk("<7>Hello kernel!\n");
        return 0;
}
                                                                             
void cleanup_module(void)
{
        printk("<7>Good-bye kernel!\n");
}
however when i try to compile and insert it i get this:
[root@localhost root]# gcc -D __KERNEL -D MODULE -O2 -W -Wall -c hello_module.c
hello_module.c: In function `init_module':
hello_module.c:16: warning: implicit declaration of function `printk'
[root@localhost root]# insmod hello_module.o
insmod: error inserting 'hello_module.o': -1 Invalid module format

if anyone could point me in the right direction it'd be greatly appreciated

23,1 All
 
Old 11-06-2004, 09:21 PM   #2
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
well for one thing fedora 2 kernel (modern) uses .ko modules
have no idea if they really differ from regular object files though ?????
first try -- just rename it.
 
Old 11-06-2004, 10:46 PM   #3
mathman0
LQ Newbie
 
Registered: Oct 2004
Distribution: Fedor Core 2
Posts: 15

Original Poster
Rep: Reputation: 0
well thanks for the info,renaming it however didn't work....but need to look into why they're doing this............heard alot of good things about FC2 but not that impressed
 
Old 11-06-2004, 10:48 PM   #4
mathman0
LQ Newbie
 
Registered: Oct 2004
Distribution: Fedor Core 2
Posts: 15

Original Poster
Rep: Reputation: 0
found a few errors in my command,am now using
[root@localhost root]# gcc -D__KERNEL__ -D__SMP__ -DMODULE -DMODVERSIONS -I/lib/modules/2.6.5-1.358/build/include -Wall -O2 -o hello_module.o -c hello_module.c
In file included from /lib/modules/2.6.5-1.358/build/include/asm/processor.h:18,
from /lib/modules/2.6.5-1.358/build/include/asm/thread_info.h:16,
from /lib/modules/2.6.5-1.358/build/include/linux/thread_info.h:21,
from /lib/modules/2.6.5-1.358/build/include/linux/spinlock.h:12,
from /lib/modules/2.6.5-1.358/build/include/linux/capability.h:45,
from /lib/modules/2.6.5-1.358/build/include/linux/sched.h:7, from /lib/modules/2.6.5-1.358/build/include/linux/module.h:10,
from hello_module.c:1:
/lib/modules/2.6.5-1.358/build/include/asm/system.h: In function `__set_64bit_var':
/lib/modules/2.6.5-1.358/build/include/asm/system.h:193: warning: dereferencing type-punned pointer will break strict-aliasing rules
/lib/modules/2.6.5-1.358/build/include/asm/system.h:193: warning: dereferencing type-punned pointer will break strict-aliasing rules

but still the same error from insmod
 
Old 11-07-2004, 01:19 PM   #5
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
Quote:
Originally posted by mathman0
...but need to look into why they're doing this...........
new kernel is a good think you just have an old example trythis
Code:
    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/kernel.h>

    static int hello_init(void)
    {
        printk(KERN_ALERT "Hello, world\n");
        return 0;
    }

    static void hello_exit(void)
    {
        printk(KERN_ALERT "Goodbye, cruel world\n");
    }

    module_init(hello_init);
    module_exit(hello_exit);
Makefile
Code:
obj-m += hello.o
default:
make -C /lib/modules/$(shell uname -r)/build/ SUBDIRS=$(PWD) modules
put a TAB before make in the Makefile

sorry i cant try this to see if it works cause my kernel is very different (compiled with icc)
 
Old 11-07-2004, 03:13 PM   #6
mathman0
LQ Newbie
 
Registered: Oct 2004
Distribution: Fedor Core 2
Posts: 15

Original Poster
Rep: Reputation: 0
thank you,it now compiles and after inserting operated fine,now i can move on to read more about device drivers thank you
 
  


Reply



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 using gcc Damitha Mandriva 1 12-17-2004 05:11 AM
Kernel compiling: gcc-3.3 is 586, should be gcc-3.3 386 Erik Plaggenmar Linux - Software 0 10-01-2004 11:38 AM
Various Compiling Errors (GCC compiling Openal, GUIlib, xmms-wma) gregorya Linux - Software 2 08-27-2004 05:03 AM
Compiling C++ GCC poeta_boy Linux - Newbie 14 10-14-2003 04:23 PM
Kernel compiling and module compiling tarballed Linux - General 1 12-22-2002 05:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:17 AM.

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