ld error

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
firas981

ld error

Post by firas981 »

ld reported a message like :
"undefiend reference f in file mainfile.c "
f is a function declared in a header , say : "file.h" and I included it in mainfile.c !!

when I put
#include "file.c" instead of #include "file.h" , things go right !

thanks
Adek336

Re:ld error

Post by Adek336 »

Um.. I don't think I understand you clearly.. would you post the code?
Cheers
Curufir

Re:ld error

Post by Curufir »

Err, short on details, but maybe because you aren't actually compiling/linking mainfile.c with file.c?

Just including the header doesn't tell the linker which file contains the code.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:ld error

Post by Pype.Clicker »

The proper approach is to
- include the header stuff.h in the main.c file
- compile both stuff.c and main.c files separately (-c)
- link them together (ld stuff.o main.o)
Post Reply