LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Fedora (https://www.linuxquestions.org/questions/fedora-35/)
-   -   unable to compile module source FC4 (https://www.linuxquestions.org/questions/fedora-35/unable-to-compile-module-source-fc4-458524/)

abk4523 06-26-2006 04:21 PM

unable to compile module source FC4
 
What am I missing? I wrote a simple module to test and cannot get it to compile. When I enter make hello I get the following:

make hello
cc hello.c -o hello
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: syntax error 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: syntax error before string constant
make: *** [hello] Error 1

I did some research, and found the following command:

make -C /usr/src/kernels/2.6.16-1.2115_FC4-i686/ M=`pwd` modules hello.c

and got the following results:

make: Entering directory `/usr/src/kernels/2.6.16-1.2115_FC4-i686'
scripts/Makefile.build:15: /root/Makefile: No such file or directory
make[1]: *** No rule to make target `/root/Makefile'. Stop.
make: *** [_module_/root] Error 2
make: Leaving directory `/usr/src/kernels/2.6.16-1.2115_FC4-i686'


I made a Makefile, contents as such:

# if KERNELRELEASE exists, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
obj-m := hello.c

# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else

KRNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

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

I was running this as root. I get these results when using this makefile:

make -C /usr/src/kernels/2.6.16-1.2115_FC4-i686/ M=`pwd` modules hello.c
make: Entering directory `/usr/src/kernels/2.6.16-1.2115_FC4-i686'
scripts/Makefile.build:197: target `/root/hello.c' doesn't match the target pattern
LD /root/built-in.o
Building modules, stage 2.
MODPOST
make: *** No rule to make target `hello.c'. Stop.
make: Leaving directory `/usr/src/kernels/2.6.16-1.2115_FC4-i686'

What did I miss? Thanks in advance.

x86processor 06-28-2006 02:49 PM

Try my simple Linux device driver examples:

http://www.shakthimaan.com/downloads.html

abk4523 06-29-2006 08:17 AM

Thanks for the help Shakthi. I downloaded your examples and extracted the Makefile, but get this error when compiling:

make -C /usr/src/kernels/2.6.17-1.2139_FC4-i686/ M=`` modules hello.c
make: Entering directory `/usr/src/kernels/2.6.17-1.2139_FC4-i686'
CHK include/linux/version.h
make[1]: *** No rule to make target `init/main.o', needed by `init/built-in.o'. Stop.
make: *** [init] Error 2
make: Leaving directory `/usr/src/kernels/2.6.17-1.2139_FC4-i686'

I was logged in as su. Any other guesses?

:newbie:

tanalam 07-06-2007 04:52 AM

hie,
Following makefile works for me in fc3
try this out
obj-m += module.o
all:
make -C /lib/modules/`uname -r`/build M=$(PWD) modules
clean:
make -C /lib/modules/`uname -r`/build M=$(PWD) clean

regards
tan...


All times are GMT -5. The time now is 11:42 AM.