Find the answer to your Linux question:
Results 1 to 7 of 7
hai friend, I got the compilation error,when i compile the program,plz tell me how to clear the error.... This is sample device driver program, test.c #include <linux/init.h> #include <linux/module.h> #include ...
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


    hai friend,
    I got the compilation error,when i compile the program,plz tell me how to clear the error....

    This is sample device driver program,
    test.c

    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/kernel.h>

    MODULE_LICENSE("Dual BSD/GPL");

    static int hello_init(void) {
    printk("<1> Hello world!\n");
    return 0;
    }

    static void hello_exit(void) {
    printk("<1> Bye, cruel world\n");
    }

    module_init(hello_init);
    module_exit(hello_exit);


    when i compile this, i got the compilation error like this....

    gcc -g -D__USE_FIXED_PROTOTYPES__ -o output test.c
    test.c:1:24: error: linux/init.h: No such file or directory
    test.c:2:26: error: linux/module.h: No such file or directory
    test.c:5: error: expected declaration specifiers or ... before string constant
    test.c:5: warning: data definition has no type or storage class
    test.c:13: warning: data definition has no type or storage class
    test.c:13: warning: parameter names (without types) in function declaration
    test.c:14: warning: data definition has no type or storage class
    test.c:14: warning: parameter names (without types) in function declaration
    make: *** [test] Error 1


    I don't know how to clear this....And this is the MAKE file for my program


    Makefile..

    CC=gcc
    CFLAGS=-g -D__USE_FIXED_PROTOTYPES__

    #Compiler flags:
    # -g -- Enable debugging

    # -D__USE_FIXED_PROTOTYPES__
    # -- Force the compiler to use the correct headers
    # -ansi -- Don't use GNU extensions. Stick to ANSI C.

    test: test.c
    $(CC) $(CFLAGS) -o output test.c

    clean: rm -f output

    Plz tell me how to clear the error..
    Thanks to all..
    Vivek

  2. #2
    Blackfooted Penguin daark.child's Avatar
    Join Date
    Apr 2006
    Location
    West Yorks
    Posts
    4,393
    Do you have glibc-devel and the kernel-headers installed on your system?

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    18
    Hello Daark.Child,

    Thanks for replied to my question.....I use ubuntu 7.10. I already installed libc6-dev. I tried to install glibc-devel-2.6-4.i386.rpm. so first i convert .rpm format to .deb format .
    then i got this package glibc-devel_2.6-4_i386.deb.
    Now i tried to install glibc-devel_2.6-4_i386.deb.But i got the error during installation ..

    This is the error,

    sundar@ubuntu2:~/Desktop$ sudo dpkg -i glibc-devel_2.6-4_i386.deb
    [sudo] password for sundar:
    (Reading database ... 138388 files and directories currently installed.)
    Unpacking glibc-devel (from glibc-devel_2.6-4_i386.deb) ...
    dpkg: error processing glibc-devel_2.6-4_i386.deb (--install):
    trying to overwrite `/usr/lib/libieee.a', which is also in package libc6-dev
    dpkg-deb: subprocess paste killed by signal (Broken pipe)
    Errors were encountered while processing:
    glibc-devel_2.6-4_i386.deb

    Plz tell me the solution to solve this problem,I am waiting for the reply..
    Thanks agian...
    vivek

  4. $spacer_open
    $spacer_close
  5. #4
    Blackfooted Penguin daark.child's Avatar
    Join Date
    Apr 2006
    Location
    West Yorks
    Posts
    4,393
    libc6-dev provides the same packages as glibc-devel so there is no need to install it. Try to avoid installing rpm packages on Debian based distros. Check whether you have the kernel source and possibly kernel headers installed. The kernel source should match the version of the kernel you are running.

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

    kernel source matches with the kernel

    HI Daarkchild

    kernel source matches with the kernel, still we are facing same problem, can you give some other program to run, please tell us what are all packages we have to install and how to configure and how to create make file, how to run make file, please explain initial itself

  7. #6
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Try this makefile, place a TAB (not spaces!) before the make commands:

    Code:
    obj-m	+= test.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
    Type "make" to make the files and "make clean" to clean them up.


    Regards

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

    compile device driver program

    Hi all ,
    It works correctly.thanks all .I think it was a good conversation about how to compile the device driver program.once again thanks all to clarify my doubts.
    thanks.
    with 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
  •