How to make gcc/ld iterate over many '-l library' when using -static?-Collection of common programming errors

A tick is, whenever possible, to add a static reference to an object of the class (or to the function) that were not linked in another cpp file of the same library (or in another library already used).

I have this situation:

  • library A with class clsA in clsA.cpp that gives the error
  • library A with foo.cpp that gives no reference errors
  • library B that uses class clsA
  • Application uses both libraries and uses classes/functions from foo.cpp

I get the unresolved reference in Application while using the object in library B that uses the clsA class.

Linking Application with library A and B give me the error. Since i use CodeLite, it’s hard to change library order. I simply put a static object in foo.cpp:

#include "clsA.h"
clsA objA;

The linker now see that clsA are referenced in library A (between foo.cpp) and will link correctly in application because foo.cpp were already linked.

But the trick works even if the object were created in a dummy function, never called, so the object would never been allocated:

// foo.cpp
#include "clsA.h"
void dummyf()
{
   clsA objA;
}

Originally posted 2013-11-09 21:07:09.