Re: hello.c,error



anganthia <angantia@xxxxxxxxx> wrote:

hey guys i am newbie and am trying to compile the famous helloworld
program and i am using the following hello.c file and the make file
also i have given and i am getting the following errors i am trying
from one week pls help

hello.c
**************************************

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

static int hello_init(void) /* Loads a module in the kernel */
{
printk(KERN_ALERT"Hello kernel\n");
return 0;

}

static void hello_exit(void) /* Removes module from kernel */
{
printk(KERN_ALERT"GoodBye Kernel\n");

}

module_init(hello_init);
module_exit(hello_exit);

makefile
****************************

ifneq ($KERNELRELEASE),)

obj-m :=hello.o

else

KERNELDIR := /lib/modules/$(shell uname -r)/build

PWD := $(shell pwd)

default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

endif

%make hello
********************************
cc -c -o hello.o hello.c
hello.c:2:24: error: linux/init.h: No such file or directory
hello.c:3:26: error: linux/module.h: No such file or directory
hello.c: In function 'hello_init':
hello.c:7: error: 'KERN_ALERT' undeclared (first use in this function)
hello.c:7: error: (Each undeclared identifier is reported only once
hello.c:7: error: for each function it appears in.)
hello.c:7: error: expected ')' before string constant
hello.c: In function 'hello_exit':
hello.c:13: error: 'KERN_ALERT' undeclared (first use in this
function)
hello.c:13: error: expected ')' before string constant
hello.c: At top level:
hello.c:16: warning: data definition has no type or storage class
hello.c:16: warning: parameter names (without types) in function
declaration
hello.c:17: warning: data definition has no type or storage class
hello.c:17: warning: parameter names (without types) in function
declaration
make: *** [hello.o] Error 1

I don't want to confuse the issue but here is one I've been tinkering
with with some reference URL's. Don't let the "main" function confuse
you. Its not what you think.

This one (only) works with a 2.6.x kernel.

hello.c
****************************************************************************
/* 010831 - Linux Journal Sept 2001 Pg 24 - Loadable Module Hello.c
- compile with
gcc -c -DMODULE -D__KERNEL__ hello.c
- Use with
insmod ./hello.o
lsmod
rmmod hello.o
050417 - http://tldp.org/LDP/lkmpg/2.6/html/index.html
- make -C /usr/src/linux-`uname -r` SUBDIRS=$PWD modules
- Makefile: obj-m += src_file.o
050922 - Repaired and made modern from Linux Journal Oct 2005 Pg
22.
http://www.linuxjournal.com/article/8453
060406 - Tried adding a main function ... it doesn't work exactly
as you'd think.
- Follow the ftp kernel module example to add a sys_call.
*/

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

#define MYKERN "<4> " /* 1=minimum, console only; 4=kernel warning,
/var/log/messages */

int main(void) {
printk(MYKERN "I'm in the main loop now!\n");
return 0;
}

int init_module() {
int x;
printk(MYKERN "Hello, kernel!\n");
x=main();
return 0;
}

void cleanup_module() {
printk(MYKERN "I'm not offended that you "
"unloaded me. Have a pleasant day!\n");
}

MODULE_AUTHOR("Linux Journal Sept 2001 & Oct 2005.");
MODULE_LICENSE("GPL");


Makefile
****************************************************************************
# 050922 - Very basic kernel module make file.
obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

clean:
rm -f *.o *.ko *.mod.c

Output
****************************************************************************
make -C /lib/modules/2.6.20/build
SUBDIRS=/usr/src/MySource/modules/26/hello modules
make[1]: Entering directory `/usr/src/linux-2.6.20'
CC [M] /usr/src/MySource/modules/26/hello/hello.o
Building modules, stage 2.
MODPOST 1 modules
CC /usr/src/MySource/modules/26/hello/hello.mod.o
LD [M] /usr/src/MySource/modules/26/hello/hello.ko
make[1]: Leaving directory `/usr/src/linux-2.6.20'

Good luck!



--
------------------------------------------------
http://www3.sympatico.ca/dmitton
SPAM Reduction: Remove "x." from my domain.
------------------------------------------------

--
Posted via a free Usenet account from http://www.teranews.com

.



Relevant Pages

  • Re: MiniDV capture over firewire - Kino
    ... MiniDV capture over firewire - Kino ... raw1394 kernel module not loaded or failure to read/write ... Although /dev/raw1394 is actually there and the permission look fine - I've changed the permission to 770 thinking that ability to execute might help. ... It might have helped because it worked for a little while and I captured a bit - but as soon as I discarded those files to do it properly it's dead again with the same old warning message. ...
    (Ubuntu)
  • Check dependencies for modules "dm-snapshot" and "sd_mod" in kernel 2.6.23.1
    ... WARNING Cannot determine dependencies of kernel module 'dm-snapshot'. ... keyboard-blink dm block usb lvm2 resume.userspace resume.kernel ...
    (Linux-Kernel)
  • Re: insmod error on FC2?
    ... You can't compile a kernel module this way. ... PWD:= $(shell pwd) ... You have your-module.c and the Makefile in the current directory, ...
    (Fedora)
  • Building a single kernel module
    ... PWD:= $(shell pwd) ... I'm trying to rebuild the via-velocity kernel module. ...
    (Fedora)