LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-18-2011, 02:07 AM   #1
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Rep: Reputation: Disabled
How to include my helloworld.c into makefile?


noob here.

following the tutorial from this site:
http://tomoyo.sourceforge.jp/cgi-bin...ld/modules.txt

I have my helloworld.c inside the /Desktop/Kernel/linux/driver/input/misc
from the website, to build my external driver I need to make

$ make -C <path_to_kernel_src> M=$PWD

I would write the following in the terminal:
laptop:~/Desktop/Kernel/linux$ make -C Desktop/Kernel/linux-2.6.37/drivers/input/misc M=$PWD helloworld.c
make: *** Desktop/Kernel/linux-2.6.37/drivers/input/misc: No such file or directory. Stop.


I get the following warning.

Anything miss out?
 
Old 10-18-2011, 02:30 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You need to specify the path of your linux kernel source, not an arbitrary directory. You can try:
Code:
make -C /lib/modules/`uname -r`/build M=$PWD
Note that you don't give the name of the .c file as argument, since the M=$PWD argument takes care of compiling all the source code in the current working directory. Just be sure the kernel sources are installed on your system.
 
Old 10-18-2011, 02:40 AM   #3
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Original Poster
Rep: Reputation: Disabled
laptop:~/Desktop/Kernel/linux/drivers/input/misc$ make -C /lib/modules/`uname -r`/build M=$PWD helloworld
make: Entering directory `/usr/src/linux-headers-2.6.32-34-generic'
gcc -m elf_i386 /home/weichons/Desktop/Kernel/linux/drivers/input/misc/helloworld.c -o helloworld
cc1: error: unrecognized command line option "-m"
make: *** [helloworld] Error 1
make: Leaving directory `/usr/src/linux-headers-2.6.32-34-generic'
 
Old 10-18-2011, 02:49 AM   #4
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Original Poster
Rep: Reputation: Disabled
laptop:~/Desktop/Kernel/linux-2.6.37/drivers/input/misc$ make -C /lib/modules/`uname -r`/build M=$PWD helloworld
make: Entering directory `/usr/src/linux-headers-2.6.32-34-generic'
gcc -m elf_i386 /home/weichons/Desktop/Kernel/linux-2.6.37/drivers/input/misc/helloworld.c -o helloworld
cc1: error: unrecognized command line option "-m"
make: *** [helloworld] Error 1
make: Leaving directory `/usr/src/linux-headers-2.6.32-34-generic'

is it something to do with my kernel version? seem like the one I am try to compile with is different from the compiler.
 
Old 10-18-2011, 03:24 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Indeed the "-m elf_i386" is an option to the linker ld. It should not appear in the gcc command line. Please, try to remove the helloworld (last) argument from your command line:
Code:
make -C /lib/modules/`uname -r`/build M=$PWD
 
Old 10-19-2011, 02:43 AM   #6
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Original Poster
Rep: Reputation: Disabled
ok, I am pretty confuse now...
Since yesterday I want to make my helloworld.c into the makefile....
so that helloworld.o being create, before I can run compile.
this is what happened..

Here is the legend,
I have another kernel on desktop where my helloworld is.
The version on desktop is linux-2.6.37.
Currently the system running on 2.6.32.

xxx@xxx-laptop:~/Desktop/Kernel/linux$ make -C /lib/modules/`uname -r`/build M=$PWD
make: Entering directory `/usr/src/linux-headers-2.6.32-34-generic'
CC kernel/bounds.s
/home/xxx/Desktop/Kernel/linux/kernel/bounds.c:1: fatal error: can’t open kernel/bounds.s for writing: Permission denied
compilation terminated.
make[1]: *** [kernel/bounds.s] Error 1
make: *** [_module_/home/xxx/Desktop/Kernel/linux] Error 2
make: Leaving directory `/usr/src/linux-headers-2.6.32-34-generic'
xxx@xxx-laptop:~/Desktop/Kernel/linux$



also, in the tutorial, it didn't specify where should I be putting my helloworld.c.
for beginner where should I put this? can just put inside driver folder?
 
Old 10-19-2011, 02:58 AM   #7
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Original Poster
Rep: Reputation: Disabled
another question is, since my system is running on 2.6.32, I do the following:

xxx@xxx-laptop:~/Desktop/Kernel/linux$ make
CHK include/linux/version.h
CHK include/generated/utsrelease.h
CALL scripts/checksyscalls.sh
CHK include/generated/compile.h
VDSOSYM arch/x86/vdso/vdso32-int80-syms.lds
VDSOSYM arch/x86/vdso/vdso32-sysenter-syms.lds
VDSOSYM arch/x86/vdso/vdso32-syms.lds
LD arch/x86/vdso/built-in.o
LD arch/x86/built-in.o
scripts/Makefile.build:44: /home/xxx/Desktop/Kernel/linux-2.6.37/drivers/debug/Makefile: No such file or directory
make[2]: *** No rule to make target `/home/xxx/Desktop/Kernel/linux-2.6.37/drivers/debug/Makefile'. Stop.
make[1]: *** [drivers/debug] Error 2
make: *** [drivers] Error 2
xxx@xxx-laptop:~/Desktop/Kernel/linux$

what will "make" command actually use ?
 
Old 10-19-2011, 03:39 AM   #8
dennisdd
Member
 
Registered: Oct 2011
Posts: 37

Original Poster
Rep: Reputation: Disabled
xxx@xxx-laptop:~/Desktop/Kernel/linux$ make -C /home/xxx/Desktop/Kernel/linux/ M=$PWD
make: Entering directory `/home/xxx/Desktop/Kernel/linux-2.6.37'
Building modules, stage 2.
MODPOST 0 modules
make: Leaving directory `/home/xxx/Desktop/Kernel/linux-2.6.37'

but stiil can finds where is the .o file.
 
  


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
[SOLVED] How to add include path to kernel module Makefile oblix Linux - Software 2 09-17-2009 07:35 PM
[SOLVED] How to add include path to kernel module Makefile oblix Linux - Kernel 2 09-16-2009 09:09 AM
Makefile include statement problem wampire Programming 1 05-21-2008 10:32 PM
Unable to include headers in Makefile Raphexion Programming 2 11-05-2005 08:00 AM

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

All times are GMT -5. The time now is 05:58 AM.

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