After reading a helpful post on the topic which describes that linker will "throw away" a library if it comes across it but none of the symbols it defines are needed, I realized that my link line was wrong. The problem was not between my executable and my library but between my two libraries. I had placed the "depended on" library first thinking that the symbols should be available when they were needed (which explains why I got errors when my executable's .o was placed before or after the libraries).
Regards, Iker
Iker Arizmendi wrote:
Just a quick follow up - when I put the static libraries _after_ the executable's .o file I get _more_ undefined reference errors.
Iker
Iker Arizmendi wrote:
Hello all.
I have a project that creates several static libraries in two directories and an executable that uses them in a third. The libraries build just fine, and the executable builds fine, but fails during linking with "undefined reference" errors. I've checked the libraries with nm and can see that the symbols the linker claims are undefined are exported (nm shows marks them with a "T"). I've checked that the link line includes the libraries and that libraries that are depended on by other libraries appear first (and before the executable's .o file). I also made sure that all the files involved were compiled with g++ and not gcc. But the errors persist.
What am I missing here? Any help greatly appreciated.
Regards, Iker