Linkage order in Linux
Ian Lance Taylor
iant@google.com
Wed Feb 10 06:17:00 GMT 2010
michael kapelko <kornerr@gmail.com> writes:
> Recently I found out a surprising requirement to compile own
> application with Horde3D library (http://horde3d.org/), OpenGL 3D
> graphics engine.
> Horde3D library links to shared GL library. But -lHorde3D must be
> listed *before* -lGL for any application to work correctly. If I link
> the application first to GL, and only then to Horde3D, then it merely
> segfaults when Horde3D's init calls glCreateShader, a GL library
> function.
> We have several speculations about what causes this particular order
> for the linker: http://horde3d.org/forums/viewtopic.php?f=2&t=384
> But I'd like to know real reason of this surprising order of linkage
> requirement.
The mailing list gcc@gcc.gnu.org is for gcc developers. Questions
about using gcc should be taken to gcc-help@gcc.gnu.org. Please take
any followups to gcc-help. Thanks.
Unix linkers are always order dependent, by design. If -lHorde3D
requires symbols from -lGL, but links successfully even if -lHorde3D
is used after -lGL, then perhaps the references in -lHorde3D are weak
for some reason. Or there are a few other possibilities; I'm not
familiar with the libraries in question.
One thing is for sure: this has nothing to do with gcc. gcc does not
include a linker. If you are using GNU/Linux, then your linker is
almost certainly coming from the GNU binutils, which is a different
project; see http://sourceware.org/binutils/ .
Ian
More information about the Gcc
mailing list