-   Linux - Newbie (
-   -   module compilation (

ktnamus 12-08-2012 08:27 AM

module compilation
i tried to compile module hello.c in linux 3.2.0-23-generic..
the error with btusb.c arrised. how to fix this error..i don't no kernel programming..

root@ubuntu:~# make
make -C /lib/modules/3.2.0-23-generic/build M= modules
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-23-generic'
  CHK    include/linux/version.h
  CHK    include/generated/utsrelease.h
  CALL    scripts/
  CC [M]  drivers/bluetooth/btusb.o
drivers/bluetooth/btusb.c:67:2: error: implicit declaration of function ‘USB_VENDOR_AND_INTERFACE_INFO’ [-Werror=implicit-function-declaration]
drivers/bluetooth/btusb.c:67:2: error: initializer element is not constant
drivers/bluetooth/btusb.c:67:2: error: (near initialization for ‘btusb_table[1].match_flags’)
drivers/bluetooth/btusb.c:116:2: error: initializer element is not constant
drivers/bluetooth/btusb.c:116:2: error:
(near initialization for ‘btusb_table[20].match_flags’)
drivers/bluetooth/btusb.c:119:2: error: initializer element is not constant
drivers/bluetooth/btusb.c:119:2: error: (near initialization for ‘btusb_table[21].match_flags’)
drivers/bluetooth/btusb.c: In function ‘btusb_probe’:
drivers/bluetooth/btusb.c:1099:6: error: ‘struct hci_dev’ has no member named ‘load_firmware’
drivers/bluetooth/btusb.c:1099:2: warning: statement with no effect [-Wunused-value]
cc1: some warnings being treated as errors
make[3]: *** [drivers/bluetooth/btusb.o] Error 1
make[2]: *** [drivers/bluetooth] Error 2
make[1]: *** [drivers] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-23-generic'
make: *** [all] Error 2

i downloaded the copy of btusb.c from LXR but gives the same errors...

knudfl 12-08-2012 08:47 AM

Which hello.c is it about ? A link please.
( I don't understand why bluetooth/* should be used.)

An example that works : Post #2 here


ktnamus 12-08-2012 08:58 AM

you mean i dont need to compile bluetooth drivers.
my helloworld program is the basic program which may be found out is first lesson of driver or module compilation....

knudfl 12-08-2012 01:25 PM

All you need to compile a simple module is an empty folder in /home/<name>/,
with hello.c and a basic module 'Makefile' like this one :

obj-m    := hello.o

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

        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

Then : $ cd <new-folder> && make : hello.ko is created.


ktnamus 12-09-2012 11:48 PM

i had these files.

int init_module(void)
return 0;
void end_module(void)


obj-m += mymodule.o

        make -C /lib/modules/$(shell uname -r)/build M=$(pwd) modules

        make -C /lib/modules/$(shell uname -r)/build M=$(pwd) clean

actualy my problem was http://
as you said i copied bound.c,but then it showed that problem for other files too. so i copied these all which were needed...and above
problem say me something atleast about where am i wrong.

knudfl 12-10-2012 05:00 AM

# 5

Don't know what's the meaning with line 12, 13 in your file :

But when those two lines are deleted, the file compiles OK :
mymodule.ko is created


ktnamus 12-15-2012 02:58 AM

i get it. but i module.o is created but has error with version

root@ubuntu:~# insmod hello.o
insmod: error inserting 'hello.o': -1 Invalid module format

how to know which versions of the packages 'kernel' and 'kernel-devel' i have and how to fix them.

knudfl 12-15-2012 04:58 AM

# 7 . The Debian / Ubuntu package names are : linux-image , linux-headers.

You already know the 'linux-headers' version : linux-headers-3.2.0-23-generic

The "kernel in use" : $ uname -r

'linux-image' and 'linux-headers' must be the same version, to make a module.
And the compiler gcc must be the same that was used to compile your working kernel.
That's most often the default gcc, but not always.
Ubuntu 12.04 : gcc-4.6.3 ?


ktnamus 12-15-2012 07:07 AM

i have gcc4.6.3,and

root@ubuntu:~# uname -r

but the differnce seen when i tried..

root@ubuntu:~# dpkg --list | grep linux-image
ii  linux-image-3.2.0-23-generic          3.2.0-23.36                            Linux kernel image for version 3.2.0 on 64 bit x86 SMP
ii  linux-image-generic                                      Generic Linux kernel image

is this difference...
i think it was because recently i downloaded headers-3.2.0-23.36,if so where i would get headers-

knudfl 12-15-2012 10:29 AM

# 9 : sudo insmod hello.ko : OK here.

These are the installed packages :

$ dpkg --list | grep linux-image
ii  linux-image-3.2.0-23-generic-pae    3.2.0-23.36                   
          Linux kernel image for version 3.2.0 on 64 bit x86 SMP
ii  linux-image-generic-pae                       
          Generic Linux kernel image

$ dpkg --list | grep linux-headers
ii  linux-headers-3.2.0-23              3.2.0-23.36                           
          Header files related to Linux kernel version 3.2.0
ii  linux-headers-3.2.0-23-generic-pae  3.2.0-23.36                           
          Linux kernel headers for version 3.2.0 on 64 bit x86 SMP
ii  linux-headers-generic-pae                             
          Generic Linux kernel headers

ktnamus 12-16-2012 12:48 AM

thank you..

All times are GMT -5. The time now is 01:58 PM.