Find the answer to your Linux question:
Results 1 to 7 of 7
hello friend, I am new to linux .i have to compile a device driver program and this is the program. #include<linux/init.h> #include<linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void) { printk(KERN_ALERT "Hello,world\n"); ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    18

    how to compile device driver program


    hello friend,
    I am new to linux .i have to compile a device driver program and this is the program.

    #include<linux/init.h>
    #include<linux/module.h>
    MODULE_LICENSE("Dual BSD/GPL");

    static int hello_init(void)
    {
    printk(KERN_ALERT "Hello,world\n");
    return 0;
    }

    static void hello_exit(void)
    {
    printk(KERN_ALERT "Goodbye,cruel world\n");
    }

    module_init(hello_init);
    module_exit(hello_exit);

    i don't know how to compile this program,If i try to compile it i got error during compilation...so plz tell me the steps to compile the device driver program........
    THANK YOU,
    VIVEK.

  2. #2
    Just Joined!
    Join Date
    Apr 2005
    Location
    Romania
    Posts
    42
    For example (compile as a module):

    gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c program.c

    But keep in mind to verify that the source code for your current kernel version is installed (if you don't have a /usr/include/linux/version.h file -> cd /usr/src/linux; make include/linux/version.h)

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    18

    Kernel source code

    Hi,
    Thank you for your quick reply. I am using ubuntu linux 7.10. I installed linux-headers-2.6.22-14-generic and linux-headers-2.6.22-14. For this where can i get the kernel source code and what is the procedure to install the source code. please let me know the details.

    thanks in advance
    vivek

  4. #4
    Just Joined!
    Join Date
    Feb 2008
    Posts
    50
    Hi Vivek,

    You can easily download source code from The Linux Kernel Archives.
    Download the stable version and compile it on your ubuntu machine.

    See this link for beginning your module programming : http://www.faqs.org/docs/kernel/

    and also try to use Makefiles instead of writing all command on terminal.

    I think that helps you...!!

    Thanks,
    Pankaj.

  5. #5
    Just Joined!
    Join Date
    Feb 2008
    Posts
    18

    Compiler Error

    hai,

    I tried to compile my program. but i got an error. i don't know the problem exactly. I include my makefile and error also.

    This is my makefile

    TARGET := module
    WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
    INCLUDE := -isystem /lib/modules/`uname -r`/build/include
    CFLAGS := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
    CC := gcc

    ${TARGET}.o: ${TARGET}.c

    .PHONY: clean

    clean: rm -rf ${TARGET}.o


    This is the error output


    sundar@ubuntu2:~/driver$ make
    gcc -O2 -DMODULE -D__KERNEL__ -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules/`uname -r`/build/include -c -o module.o module.c
    In file included from /lib/modules/2.6.22-14-generic/build/include/asm/thread_info.h:16,
    from /lib/modules/2.6.22-14-generic/build/include/linux/thread_info.h:21,
    from /lib/modules/2.6.22-14-generic/build/include/linux/preempt.h:9,
    from /lib/modules/2.6.22-14-generic/build/include/linux/spinlock.h:49,
    from /lib/modules/2.6.22-14-generic/build/include/linux/module.h:9,
    from module.c:2:
    /lib/modules/2.6.22-14-generic/build/include/asm/processor.h:83: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)
    /lib/modules/2.6.22-14-generic/build/include/asm/processor.h:83: error: requested alignment is not a constant
    In file included from /lib/modules/2.6.22-14-generic/build/include/linux/module.h:21,
    from module.c:2:
    /lib/modules/2.6.22-14-generic/build/include/asm/module.h:64:2: error: #error unknown processor family
    make: *** [module.o] Error 1
    sundar@ubuntu2:~/driver$

    Please let me know the exact problem and how to solve this problem


    Regards
    vivek

  6. #6
    Just Joined!
    Join Date
    Feb 2008
    Posts
    50
    Are you did this:
    ln -s /usr/src/linux/include/ /lib/modules/2.6XXXXX/build/

    This creates a symbolic link of a directory "include" within "build" pointing to /usr/src/linux/include/.

    Thanks,
    Pankaj.

  7. #7
    Just Joined!
    Join Date
    Feb 2008
    Posts
    18

    how to compile device driver program

    hai Mr Pankaj,

    I did that step. but the same error is continuing.

    Regards
    vivek

Posting Permissions

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