I've run into a tough "undefined reference" error when trying to build a module in Linux with C++. I'm going to describe it at a high level, and post code later if necessary (it's proprietary, so posting it would require some name changing). Some details:
- Module A (a library) has a class that we'll call Foo with a method called Bar. Module A builds just fine, and using nm to look at the object file shows that the constructor and Bar are both defined (they show up as 'T').
- Module B (a library) contains a class that uses module A, with references to Foo::Foo, Foo::~Foo, and Foo::Bar. Its makefile includes -L/path/to/Foo and -lFoo. This module also builds just fine. However, when I run nm on Module B's object file, the calls to module Foo::Foo, Foo::~Foo, and Foo::Bar are undefined (they show up as 'U'). Why it builds is beyond me.
Module C - whose output is an executable - contains references to module B. When I try to build Module C, then it yells at me for the undefined reference from Module B to Module A's Foo and Bar methods.
- Why does module B build if a reference is undefined?
- Why is the error only reported once we get to Module C?
EDIT:
- I should mention that Module C's makefile also has -L/path/to/Foo and -lFoo, but it still fails. Any high-level guesses as to anything I should try? I have a feeling I'm going to have to post some code...