0

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?

Majubs
  • 41
  • 6
  • 2
    it's not an include problem (as it successfully compile file.c), the linker try to find the implementation of the function, header.o must not be given to the linker – Guiroux Mar 10 '15 at 15:33
  • 2
    You still need to compile and link `header.c`. – Biffen Mar 10 '15 at 15:33
  • Ok, but how do I do it? I edited the question with more information – Majubs Mar 12 '15 at 13:57

0 Answers0