So as I mentioned in here, I'm doing some changes to the Linux Kernel.
Right now, the changes are very small, but to isolate them, I want my stuff to be in its own file.
My changes basically redefine some functions and as such, they rely on functions in a parent file.
So foo.c
contains:
/* headers.h does not contain a prototype my_fun2*/
#include "headers.h"
static void fun1(){
...
}
void fun2(){
...
fun1()
}
And my_foo.c
contains:
/* headers.h does not contain a prototype my_fun2*/
#include "headers.h"
/* Note: I'm not #include "foo.c" */
extern void fun1();
void my_fun2()
{
...
fun1()
}
You'll note that in my_foo.c
I have extern void fun1()
and not extern static void fun1()
because this apparently causes a conflict due to storage classes. Further explanation on this would be nice.
Now that I have my code the way I want it, I'll edit the corresponding Makefile
to have the following
obj-$(CONFIG_MY_FOO) +=foo.o my_foo.o
With all of this put together though, it doesn't seem to work. I've used make files before and normally a recipe would be:
foo: foo.o bar.o
$(cc) foo.o bar.o -o foo
foo.o: foo.c
$(cc) -c foo.c
bar.o: bar.c
$(cc) -c bar.c
However, this doesn't seem to be the format in the Linux Kernel Makefiles. So when I run make
I get the following error:
my_foo.c:XX: undefined reference to `fun1()'
What am I missing? Do I just need to copy the functions to my_foo.c
because fun1()
is static?