Printable Version of Topic

Click here to view this topic in its original format

Linuxhelp _ Programming in Linux _ Linux Kernel Newbie

Posted by: nkhambal Jun 9 2005, 01:08 AM

Hi,

I just started learning Linux device driver programming. I have been trying to compile this "hello, world" program on Fedora Core 3. But I am unable to do so. Following is Code.

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

MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
       printk(KERN_ALERT "HELLO, WORLDn");
       return 0;
}

static void hello_exit(void)
{
       printk(KERN_ALERT "GOOD BYE, WORLDn");
}

module_init(hello_init);
module_exit(hello_exit);


When I compile I get following errors

[quote]
[root@devlinux snoopy]# gcc -c mod1.c
mod1.c: In function `hello_init':
mod1.c:9: error: `KERN_ALERT' undeclared (first use in this function)
mod1.c:9: error: (Each undeclared identifier is reported only once
mod1.c:9: error: for each function it appears in.)
mod1.c:9: error: syntax error before string constant
mod1.c: In function `hello_exit':
mod1.c:15: error: `KERN_ALERT' undeclared (first use in this function)
mod1.c:15: error: syntax error before string constant
[root@devlinux snoopy]#
[/quote]

Can someone help me with this problem ?

Following is my Kernel Version

[quote]
[root@devlinux snoopy]# uname -a
Linux devlinux 2.6.9-1.667 #1 Tue Nov 2 14:41:25 EST 2004 i686 i686 i386 GNU/Linux
[root@devlinux snoopy]#
[/quote]

and my gcc version
[quote]
[root@devlinux snoopy]# gcc -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
[root@devlinux snoopy]#
[/quote]

Posted by: Corey Jun 13 2005, 06:26 AM

I'm no programmer, but i've dabbled in C from time to time.

At first glance, i would guess you're missing a comma between your loglevel and message:

QUOTE
        printk(KERN_ALERT "HELLO, WORLDn");


should be

QUOTE
        printk(KERN_ALERT, "HELLO, WORLDn");


You'll want to fix both entires of this.

But, like i said, i'm no programmer, this is just a guess. I don't know how else the compiled would be able to tell the what's what without it smile.gif

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)