delorie.com/djgpp/faq/dev-probs/link-order.html   search  
I give all the libraries to gcc, but I still get unresolved externals when I link. What gives?

There are two things to check here.

First, ld is a one-pass linker, it only scans each library once looking for unresolved externals it saw until that point. This means the relative position of object files and library names on the command line is significant. First, you should put all the libraries after all the object files. Second, put them in this order:

  -lgpp -lgpl -lm -lpc
If you have any libraries of your own, put them before the above system libraries.

Second, some C++ functions are declared inline. However, gcc won't inline them unless you compile with optimizations enabled, so it tries to find the compiled version of the functions in the library. Workaround: compile with -O.

  webmaster     delorie software   privacy  
  Copyright © 1995     Updated Feb 1995