1

I want to compile statically pdf2svg so I will be able to use newest version in stable Debian. The ./configure doesn't give --enable-static option so I added manually in Makefile -static option for linker.

Unfortunately the result wasn't quite as I suspected. The linking gave me enormous amounts of undefined reference errors. After some googling I figured out that the problem is caused by wrong order of -lsome_lib. Gcc linker tries to statically link in each library once, when it first sees it - info and Stackoverflow question: Why does the order in which libraries are linked sometimes cause errors in GCC?.

Is there a possibility of making linker make multiple passes through the list of libraries?

Community
  • 1
  • 1
Yax
  • 436
  • 3
  • 12

2 Answers2

9

Maybe this is what you search for (from gnu ld manpage):

   -( archives -)
   --start-group archives --end-group
       The archives should be a list of archive files.  They may be either explicit file names, or -l options.

       The specified archives are searched repeatedly until no new undefined references are created.  Normally, an archive is searched only once in the order that it is
       specified on the command line.  If a symbol in that archive is needed to resolve an undefined symbol referred to by an object in an archive that appears later on
       the command line, the linker would not be able to resolve that reference.  By grouping the archives, they all be searched repeatedly until all possible references
       are resolved.

       Using this option has a significant performance cost.  It is best to use it only when there are unavoidable circular references between two or more archives.
PlasmaHH
  • 15,673
  • 5
  • 44
  • 57
  • This is the answer for the question, but unfortunately it didn't help me. I ended with using so libraries and LD_LIBRARY_PATH. – Yax Jan 23 '12 at 09:11
0

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;
}
stegemma
  • 21
  • 2