Results 1 to 6 of 6
i want to compile 3 file like this : a.c & b.c & d.h
a.c is:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO ...
- 07-08-2011 #1Just Joined!
- Join Date
- Jul 2011
- Posts
- 7
compile 2 dependent file a.c and b.c with a header d.h
i want to compile 3 file like this : a.c & b.c & d.h
a.c is:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include "ALU.h"
int init_module(void)
{
int a=2,b=3;
printk(KERN_INFO "add example a=%d" b1_module(a,b));
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
//-----------------------------------------------------------------------------
b.c:
#include "d.h"
static int b1_module( int a , int b )
{
.....
return R;
}
//----------------------------------------------------------------------------
d.h:
#ifndef __d_H__
#define __d_H__
//---------------------------------------------------------------------------------
//#include <linux/module.h>
static int b1_module(int a , int b);
#endif // __d_H__
how can i write makefile for this or compile anywhy?
My Linux is 2.6.
- 07-11-2011 #2
gcc -c will probably do the trick for the object files, though you might want to include a -I<path/to/include> option in there.
As for the linker, I don't know what type of binary image you need. Is it relocatable or flat binary? man ld might get you started there, and maybe look at the way the Linux kernel compiles things. It has taught me a lot for my own home made kernel. Although I've been looking at Linux-0.0.1
- 07-13-2011 #3Just Joined!
- Join Date
- Jul 2011
- Posts
- 2
gcc -I/<path of d.h> -o executable a.c b.c
- 07-13-2011 #4
This works, but only if the files aren't dependent of each other.
This'll make the code relocatable, and might just be better when dependent of symbols defined in the core binary (could be the linux kernel image, but also something you might link into).Code:gcc -c {a,b}.c ld -R <any necessary other options> -o <output name>
- 07-23-2011 #5Just Joined!
- Join Date
- Jul 2011
- Posts
- 7
thanks a lot i have solved this problem with a makefile that introduce kernel headers i have to compile the kernel for this porpuse -I/include path and -d __KERNEL
- 07-30-2011 #6Just Joined!
- Join Date
- Jul 2011
- Posts
- 16
Use the following makefile, no need to compile the kernel.
vim Makefile
obj-m := test.o
test-objs := a.o b.o
KDIR=/lib/modules/$(shell uname -r)/build
all:
make -C $(KDIR) M=$(PWD) modulesLast edited by MikeTbob; 07-30-2011 at 07:49 PM. Reason: Deleted advertising


Reply With Quote

