Welcome! Log In Create A New Profile


makefile for multiple source files problem

Posted by vl 
I have my basic module 'hello.c':
#include <linux/module.h>
#include <linux/kernel.h>

#include "test.h"

int init_module(void)
printk("<1>Hello world 1. init_module\n"winking smiley;

// function called from test.c


return 0;

void cleanup_module(void)
printk("Goodbye world 1.\n"winking smiley;

The function "test" declared in test.h
void test(void);
and defined in "test.c":
#include <linux/module.h>
#include "test.h"

void test()
printk("test performed!\n"winking smiley;

Here's the makefile:
obj-m += hello.o
obj-m += testo.o
testo-objs := test.o

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

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

The make creates testo.ko but doesn't link test.o to the hello module.
I've found this approach in multiple tutorials but it doesn't seem to work.
Any idea how to do it correctly?
see [code.google.com]
for a good example of multiple source files and having sub-folders.

per your case, do like the below:
MODNAME := helloworld
obj-m := ${MODNAME}.o 
${MODNAME}-y :=
${MODNAME}-y += test.o hello.o

you'll get helloworld.ko.

btw, could also try
obj-m := ${MODNAME}.o  
${MODNAME}-objs+= test.o hello.o

The Effo Staff
Effo Project, [effo.sourceforge.net]

Your Email:


Spam prevention:
Please, solve the mathematical question and enter the answer in the input field below. This is for blocking bots that try to post this form automatically.
Question: how much is 21 plus 24?