Re: kernel module compilation error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 23 Sep 2005 19:13:50 +0530
Panthini <panthini.pandit@xxxxxxxxxxxxxx> wrote:

> Following is the screenshot of compilation process:
>        [root@localhost root]# gcc -Wall -O2 -D__KERNEL__ -DMODULE 
> -I/usr/src/linux-2.4.21-27.EL/include/ hello.c
>        
> /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/../../../crt1.o(.text+0x18): 
> In         function `_start':
>       : undefined reference to `main'
>        collect2: ld returned 1 exit status
>        [root@localhost root]#
> /***************************************/    
> why this is referring to 'main' even though I have not written any 
> main() function in hello.c.

gcc automatically links agains libc & libgcc unless instructed not to
do it (-nostdlib). Alternatively, you could link with ld instead of gcc.

But building modules that way (with your own compiler command line &
options) is strongly discouraged. You should use the kernel build
system even when building external modules. See
http://lwn.net/Articles/21823/ for details, most of it applies to
recent 2.4 kernels too.

Here's a simple makefile that works for me on AS 3.0:


#########################################

O_TARGET := hello_module.o

obj-y    := hello.o

obj-m    := $(O_TARGET)

include $(TOPDIR)/Rules.make

#########################################

Then you can build with the following command:

make -C /lib/modules/`uname -r`/build modules SUBDIRS=`pwd`

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux