LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (http://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Unable to compile "hello world" module on openSuse11 (http://www.linuxquestions.org/questions/linux-kernel-70/unable-to-compile-hello-world-module-on-opensuse11-662148/)

knockout_artist 08-12-2008 12:49 AM

Unable to compile "hello world" module on openSuse11
 
Good day,

Same module install/works on FC6 machine.
here are the out puts.

MAke file
Code:


champ@linux-r9za:~/driver> ls
Makefile  hello-1.c

champ@linux-r9za:~/driver> cat Makefile

bj-m += hello-1.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Hello world module, it complie runs on my FC6 machine.
Code:

champ@linux-r9za:~/driver>
champ@linux-r9za:~/driver> cat hello-1.c
#include <linux/module.h>        /* Needed by all modules */
#include <linux/kernel.h>        /* Needed for KERN_INFO */

int init_module(void)
{
        printjkk(KERN_INFO "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_INFO "Goodbye world 1.\n");
}

Build process:
Code:


champ@linux-r9za:~/driver> make
make -C /lib/modules/2.6.25.5-1.1-pae/build M=/home/champ/driver modules
make[1]: Entering directory `/usr/src/linux-2.6.25.5-1.1-obj/i386/pae'
make -C /usr/src/linux-2.6.25.5-1.1 O=/usr/src/linux-2.6.25.5-1.1-obj/i386/pae/. modules
  Building modules, stage 2.
  MODPOST 0 modules
make[1]: Leaving directory `/usr/src/linux-2.6.25.5-1.1-obj/i386/pae'
champ@linux-r9za:~/driver> champ@linux-r9za:~/driver> ls
Makefile  Module.symvers  hello-1.c  modules.order
champ@linux-r9za:~/driver>


I think I have every thing installed
Code:

champ@linux-r9za:~/driver> rpm -aq | grep kernel
kernel-pae-2.6.25.5-1.1
linux-kernel-headers-2.6.25-8.1
kernel-source-2.6.25.5-1.1
kernel-syms-2.6.25.5-1.1
champ@linux-r9za:~/driver>


Any Ideas?

Thanks.

unikgila 08-12-2008 12:57 AM

I used the Redhat, but i used the gcc instead of make. How about change your Makefile with this one:

Makefile
Code:

#Makefile for buidling a module, 08/06/2008
CC=gcc

MODCFLAGS := -O2 -Wall -DMODULE -D__KERNEL__ -DLINUX -I/usr/include

all:    hello-1.o hello-3.o hello-4.o hello-5.o



hello-1.o:      hello-1.c
                $(CC) $(MODCFLAGS) -c hello-1.c

hello-3.o:      hello-3.c
                $(CC) $(MODCFLAGS) -c hello-3.c


hello-4.o:      hello-4.c
                $(CC) $(MODCFLAGS) -c hello-4.c


hello-5.o:      hello-5.c
                $(CC) $(MODCFLAGS) -c hello-5.c

clean:
                rm -f hello-1.o hello-3.o hello-4.o hello-5.o


knockout_artist 08-12-2008 01:03 AM

Thanks.

I tried your make file that what I got

Code:

champ@linux-r9za:~/driver> make
Makefile:11: *** missing separator (did you mean TAB instead of 8 spaces?).  Stop.


unikgila 08-12-2008 01:11 AM

Yes using tab instead of spaces

unikgila 08-12-2008 01:13 AM

Yes using tab instead of spaces

knockout_artist 08-12-2008 01:57 AM

I used command from your makefile thats what I got now


Code:

champ@linux-r9za:~/driver> gcc -O2 -Wall -DMODULE -D__KERNEL__ -DLINUX -I/usr/include -c hello-1.c
hello-1.c:1:54: error: linux/module.h: No such file or directory
hello-1.c: In function 'init_module':
hello-1.c:6: warning: implicit declaration of function 'printk'
hello-1.c:6: error: 'KERN_INFO' undeclared (first use in this function)
hello-1.c:6: error: (Each undeclared identifier is reported only once
hello-1.c:6: error: for each function it appears in.)
hello-1.c:6: error: expected ')' before string constant
hello-1.c: At top level:
hello-1.c:14: error: expected identifier or '(' before '{' token
champ@linux-r9za:~/driver>


unikgila 08-12-2008 04:58 AM

Ehm, i don't know why you don't have module.h. Have you look in linux directory? just using ls command:

ls /usr/include/linux/module.h

if no try to locate where is module.h, or may be you also can try find in the kernel source
ls /usr/src/linux(your version)/include/linux/module.h

if you find it here, i think you have to modify your Makefile using above path.


All times are GMT -5. The time now is 10:05 AM.