GCC 4.4.3, Ubuntu.
3 projects:
- A (static library) build OK
- B (static library) build OK
- X (shared library or console app) linker error
Why this case not let link X?
X calls B;
B calls A; // WHY???? linker error in X: B has undefined reference to stuff in A
This case works:
X calls A; // this fact allows B access A
X calls B;
B calls A; // Now X linked just fine
Full code:
//////////////////////////////
// StaticAAA.cpp
void FunctionAAA()
{
}
//////////////////////////////
// StaticBBB.cpp
void FunctionAAA();
void FunctionBBB()
{
FunctionAAA();
}
//////////////////////////////
// App.cpp
void FunctionAAA();
void FunctionBBB();
int main()
{
#ifdef WHY_LINKER_ERROR_FIXED
FunctionAAA();
#endif
FunctionBBB();
return 0;
}
The order of libraries on the gcc command line is important – you need to list the libraries in dependency order. If you have any circular dependencies then you may need to list at least one library twice in order to satisfy this requirement.
In your particular case you probably want something like: