I'm having some trouble building a project. I'll try to reproduce the error here.
I have a file.c
where I want to use function()
that is declared in header.h
and defined in header.c
(that isn't in the same directory as header.h
).
So far very simple, I added #include "header.h"
in file.c
and the option -I/path/to/header
to the compiler, since header.h
isn't in any other include path.
I thought this should be enough for the linker to find the definition of function()
, but I still get the error
Undefined reference to 'function'
Now it gets a bit more complicated, the project is quite big, and file.c
and header.h
are in very different paths, I don't know if that makes any difference since I include the full path for the compiler.
Also, the building process first generates a file.o
, that is parcially linked with others .o
, which is after linked with with more .o
, that generates an executable, and is at the point of genereting the executable that the error occurs.
I did nm
to the partial .o
to try to get more information, and the function()
appears as undefined, which I guess is expected, but I don't know why the linker isn't able to find the definition of function()
. I have no idea what I'm missing here...
Help please?
EDIT:
I know header.c
is compiled before file.c
, but if I simply try to add header.o
to the command line, I get another error:
No rule to make target 'header.o', needed by 'file.o'
I imagine this is because the directories are different, is there any way to give the path to header.o
to the linker?