LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to include my helloworld.c into makefile? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-include-my-helloworld-c-into-makefile-908717/)

dennisdd 10-18-2011 02:07 AM

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?

colucix 10-18-2011 02:30 AM

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.

dennisdd 10-18-2011 02:40 AM

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'

dennisdd 10-18-2011 02:49 AM

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.

colucix 10-18-2011 03:24 AM

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

dennisdd 10-19-2011 02:43 AM

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?

dennisdd 10-19-2011 02:58 AM

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 ?

dennisdd 10-19-2011 03:39 AM

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.


All times are GMT -5. The time now is 06:21 AM.