This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Linkage order in Linux
- From: Ian Lance Taylor <iant at google dot com>
- To: michael kapelko <kornerr at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 09 Feb 2010 22:16:57 -0800
- Subject: Re: Linkage order in Linux
- References: <4B724C2E.2080700@gmail.com>
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