LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-08-2012, 07:27 AM   #1
ktnamus
LQ Newbie
 
Registered: Dec 2012
Posts: 10

Rep: Reputation: Disabled
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..
Code:
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/checksyscalls.sh
  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...

Last edited by ktnamus; 12-08-2012 at 07:31 AM.
 
Old 12-08-2012, 07:47 AM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
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
http://www.linuxquestions.org/questi...-4175439338/#2


.
 
Old 12-08-2012, 07:58 AM   #3
ktnamus
LQ Newbie
 
Registered: Dec 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
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....
 
Old 12-08-2012, 12:25 PM   #4
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
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 :
Code:
obj-m    := hello.o

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

default:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
Then : $ cd <new-folder> && make : hello.ko is created.

.
 
Old 12-09-2012, 10:48 PM   #5
ktnamus
LQ Newbie
 
Registered: Dec 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
i had these files.
Code:
#include<linux/module.h>
#include<linux/kernel.h>
int init_module(void)
{
printk(KERN_INFO "HELLO WORLD");
return 0;
}
void end_module(void)
{
printk(KERN_INFO "GOOD BYE");
}
module_init(init_module);
module_exit(end_module);
Code:
obj-m += mymodule.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
actualy my problem was http://http://www.linuxquestions.org...em-4175439981/
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 came..so say me something atleast about where am i wrong.

Last edited by ktnamus; 12-09-2012 at 10:54 PM.
 
Old 12-10-2012, 04:00 AM   #6
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
# 5

Don't know what's the meaning with line 12, 13 in your file :
module_init(init_module);
module_exit(end_module);

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


.
 
Old 12-15-2012, 01:58 AM   #7
ktnamus
LQ Newbie
 
Registered: Dec 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
i get it. but i module.o is created but has error with version
Code:
root@ubuntu:~# insmod hello.o
insmod: error inserting 'hello.o': -1 Invalid module format
root@ubuntu:~#
how to know which versions of the packages 'kernel' and 'kernel-devel' i have and how to fix them.
 
Old 12-15-2012, 03:58 AM   #8
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
# 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 ?

.
 
Old 12-15-2012, 06:07 AM   #9
ktnamus
LQ Newbie
 
Registered: Dec 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
i have gcc4.6.3,and
Code:
root@ubuntu:~# uname -r
3.2.0-23-generic
but the differnce seen when i tried..
Code:
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                    3.2.0.23.25                             Generic Linux kernel image
root@ubuntu:~#
is this difference...
i think it was because recently i downloaded headers-3.2.0-23.36,if so where i would get headers-3.2.0.23.25

Last edited by ktnamus; 12-15-2012 at 06:14 AM.
 
Old 12-15-2012, 09:29 AM   #10
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
# 9 : sudo insmod hello.ko : OK here.

These are the installed packages :
Code:
$ 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              3.2.0.23.25                    
           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            3.2.0.23.25                             
           Generic Linux kernel headers
 
1 members found this post helpful.
Old 12-15-2012, 11:48 PM   #11
ktnamus
LQ Newbie
 
Registered: Dec 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
thank you..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
module compilation problem ktnamus Linux - Kernel 6 12-09-2012 04:53 AM
Module compilation in Linux - 2.6.17 asahlot Linux - Kernel 0 02-16-2007 05:12 AM
Module Compilation thirumalai Linux - Software 0 08-13-2004 12:20 AM
module compilation aliyildiz Linux - General 6 03-31-2003 03:11 PM
module compilation aliyildiz Linux - General 0 12-08-2001 01:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration