Find the answer to your Linux question:
Results 1 to 6 of 6
Hi How do I compile c source code using gcc so that it would produce .ko objects for kernel module development? I'm trying to use Eclipse to manage development projects ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2008
    Posts
    12

    GCC and Kernel Development [compile help]


    Hi

    How do I compile c source code using gcc so that it would produce .ko objects for kernel module development? I'm trying to use Eclipse to manage development projects but can't use the build feature just yet since I don't know what to put in.

    Thanks.

  2. #2
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    does eclipse even support a C IDE? if you want to do kernel development you will need to install the linux-headers and build-essential packages, I think it would be
    Code:
    sudo apt-get install build-essential linux-headers-`uname -r`
    if you are looking for how to do kernel module development, I would start here: Linux Device Drivers, Third Edition [LWN.net]

  3. #3
    Just Joined!
    Join Date
    Jul 2008
    Posts
    12

    re

    Quote Originally Posted by coopstah13 View Post
    does eclipse even support a C IDE? if you want to do kernel development you will need to install the linux-headers and build-essential packages, I think it would be
    Code:
    sudo apt-get install build-essential linux-headers-`uname -r`
    Eclipse has CDT (C/C++ Development Tools) and I've already done some C/C++ projects using it. I don't know how to set it up to automate the building of kernel modules from C source code. I usually do it by manually creating the Makefiles as stated in tutorials. If I can use the gcc command (with corresponding options) than I can set it up in Eclipse.

  4. #4
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    So you just need to know how to create a make file that will build a kernel module? You want to generate this makefile automatically or manually? The link in my previous post will show you how to create a make file that will compile a kernel module. If you need to automate this, you will need to look into using some kind of configure script, I'm sure there are many tutorials you can find on configure scripts by searching google.

  5. #5
    Just Joined!
    Join Date
    Jul 2008
    Posts
    12
    Quote Originally Posted by coopstah13 View Post
    So you just need to know how to create a make file that will build a kernel module? You want to generate this makefile automatically or manually? The link in my previous post will show you how to create a make file that will compile a kernel module. If you need to automate this, you will need to look into using some kind of configure script, I'm sure there are many tutorials you can find on configure scripts by searching google.
    I tried compiling two .c files using the Makefile found in the Linux Device Drivers book. However it always fails. I can only compile one file and it should have the same name as the driver I'm compiling.

  6. #6
    Just Joined!
    Join Date
    Jul 2008
    Posts
    12
    Quote Originally Posted by coopstah13 View Post
    So you just need to know how to create a make file that will build a kernel module? You want to generate this makefile automatically or manually? The link in my previous post will show you how to create a make file that will compile a kernel module. If you need to automate this, you will need to look into using some kind of configure script, I'm sure there are many tutorials you can find on configure scripts by searching google.
    I got the makefile working but I couldn't compile 2 or more source codes.

    I have 2 files named nothing.c and hello.c

    Here's my current makefile:
    Code:
    obj-m := test.o
    module-objs := nothing.o hello.o
    
    default:
    	make -C /lib/modules/`uname -r`/build M=`pwd` modules
    I wanted to produce a kernel module named test.ko but it produces this error:
    make -C /lib/modules/`uname -r`/build M=`pwd` modules
    make[1]: Entering directory `/usr/src/linux-headers-2.6.28-15-generic'
    make[2]: *** No rule to make target `/home/rba1988/Desktop/test.c', needed by `/home/rba1988/Desktop/test.o'. Stop.
    make[1]: *** [_module_/home/rba1988/Desktop] Error 2
    make[1]: Leaving directory `/usr/src/linux-headers-2.6.28-15-generic'
    make: *** [default] Error 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •