FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora Development

 
 
LinkBack Thread Tools
 
Old 03-26-2010, 04:38 AM
Lubomir Rintel
 
Default Linker trouble

Hi,

I'm wondering if anyone could enlighten me about why does --as-needed
make a difference here? (let alone the order in which -lGL appears).

[lkundrak@localhost VirtualBox-3.1.6_OSE]$ g++ -Wl,--as-needed
> -o out/linux.x86/release/obj/VBoxTestOGL/VBoxTestOGL
> out/linux.x86/release/obj/VBoxTestOGL/generic/OpenGLTestApp.o
> -L/usr/X11R6/lib -L/usr/lib
> -lGL
> obj/lib/VBoxOGLhostspuload.a obj/bin/VBoxOGLhostcrutil.so obj/lib/VBoxOGL2D.a
> obj/bin/VBoxRT.so obj/bin/VBoxRT.so obj/lib/VBoxREM.so obj/bin/VBoxVMM.so
> -lXcursor -lXext -lX11
> obj/lib/VBoxCOM.a obj/bin/VBoxXPCOM.so
> /usr/lib/libQtCore.so /usr/lib/libQtGui.so /usr/lib/libQtOpenGL.so
/usr/bin/ld: obj/lib/VBoxOGL2D.a(VBoxGLSupportInfo.o): undefined reference to symbol 'glGetString'
/usr/bin/ld: note: 'glGetString' is defined in DSO /usr/lib/libGL.so so try adding it to the linker command line
/usr/lib/libGL.so: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
[lkundrak@localhost VirtualBox-3.1.6_OSE]$ g++ -Wl,--as-needed
> -o out/linux.x86/release/obj/VBoxTestOGL/VBoxTestOGL
> out/linux.x86/release/obj/VBoxTestOGL/generic/OpenGLTestApp.o
> -L/usr/X11R6/lib -L/usr/lib
> obj/lib/VBoxOGLhostspuload.a obj/bin/VBoxOGLhostcrutil.so obj/lib/VBoxOGL2D.a
> -lGL
> obj/bin/VBoxRT.so obj/bin/VBoxRT.so obj/lib/VBoxREM.so obj/bin/VBoxVMM.so
> -lXcursor -lXext -lX11
> obj/lib/VBoxCOM.a obj/bin/VBoxXPCOM.so
> /usr/lib/libQtCore.so /usr/lib/libQtGui.so /usr/lib/libQtOpenGL.so
[lkundrak@localhost VirtualBox-3.1.6_OSE]$ g++
> -o out/linux.x86/release/obj/VBoxTestOGL/VBoxTestOGL
> out/linux.x86/release/obj/VBoxTestOGL/generic/OpenGLTestApp.o
> -L/usr/X11R6/lib -L/usr/lib
> -lGL
> obj/lib/VBoxOGLhostspuload.a obj/bin/VBoxOGLhostcrutil.so obj/lib/VBoxOGL2D.a
> obj/bin/VBoxRT.so obj/bin/VBoxRT.so obj/lib/VBoxREM.so obj/bin/VBoxVMM.so
> -lXcursor -lXext -lX11
> obj/lib/VBoxCOM.a obj/bin/VBoxXPCOM.so
> /usr/lib/libQtCore.so /usr/lib/libQtGui.so /usr/lib/libQtOpenGL.so
[lkundrak@localhost VirtualBox-3.1.6_OSE]$

Thank you,
Lubo

--
Flash is the Web2.0 version of blink and animated gifs.
-- Stephen Smoogen

--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 
Old 03-26-2010, 01:02 PM
Charley Wang
 
Default Linker trouble

Hi Lubomir,

Not 100% clear on this, so anyone who has more experience please feel free
to correct me.

In general, as-needed means that items specified on the command line may
not be linked if they are not needed for any objects preceding them in
the command line.

I believe this is what is happening:

Case 1 (as-needed, failure):
The symbol from -lGL that failed was not needed by anything preceding -lGL
on the command line. Since the as-needed flag is set, g++ just moves on
without linking anything. A later object on the command line
do require the symbol, but by then the -lGL is no longer in play so there
is nothing left to resolve the symbol with.

Case 2 (as-needed, success):
Because -lGL is called _after_ the .o that requires it, the symbols are
correctly linked. When g++ encounters -lGL, it determines that a symbol
is required by one of the preceding objects and links accordingly.

Case 3 (without as-needed):
Without as-needed the default behaviour is to just link everything
that is on the command line, so it does not really matter where on the line
-lGL is specified.

Hope it helps!

-Charley
--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 
Old 03-26-2010, 02:16 PM
Adam Jackson
 
Default Linker trouble

On Fri, 2010-03-26 at 06:38 +0100, Lubomir Rintel wrote:
> Hi,
>
> I'm wondering if anyone could enlighten me about why does --as-needed
> make a difference here? (let alone the order in which -lGL appears).

Because order matters.

Linker arguments are positional. Object files are walked left to right
along the command line, and are added to the link in order. Archive
members are added to the link output if and only if a symbol in that
archive member satisfies a reference to a symbol mentioned earlier in
the link. --as-needed extends this behaviour to DSOs, such that
libraries will only be added to the link if they satisfy a symbol
reference from an earlier object.

So in your first link line:

> [lkundrak@localhost VirtualBox-3.1.6_OSE]$ g++ -Wl,--as-needed
> > -o out/linux.x86/release/obj/VBoxTestOGL/VBoxTestOGL
> > out/linux.x86/release/obj/VBoxTestOGL/generic/OpenGLTestApp.o
> > -L/usr/X11R6/lib -L/usr/lib
> > -lGL
> > obj/lib/VBoxOGLhostspuload.a obj/bin/VBoxOGLhostcrutil.so obj/lib/VBoxOGL2D.a
> > obj/bin/VBoxRT.so obj/bin/VBoxRT.so obj/lib/VBoxREM.so obj/bin/VBoxVMM.so
> > -lXcursor -lXext -lX11
> > obj/lib/VBoxCOM.a obj/bin/VBoxXPCOM.so
> > /usr/lib/libQtCore.so /usr/lib/libQtGui.so /usr/lib/libQtOpenGL.so

OpenGLTestApp.o is added. libGL is looked at, but not added, since the
first .o (presumably) doesn't mention any symbol defined in libGL.
Later you add the VBoxOGL2D.a archive; VBoxGLSupportInfo.o provides some
symbol that one of the earlier objects needs, but adds references to
symbols that happen to be defined in libGL. At no point later do you
mention libGL again. [1] Therefore:

> /usr/bin/ld: obj/lib/VBoxOGL2D.a(VBoxGLSupportInfo.o): undefined reference to symbol 'glGetString'

Whereas:

> [lkundrak@localhost VirtualBox-3.1.6_OSE]$ g++ -Wl,--as-needed
> > -o out/linux.x86/release/obj/VBoxTestOGL/VBoxTestOGL
> > out/linux.x86/release/obj/VBoxTestOGL/generic/OpenGLTestApp.o
> > -L/usr/X11R6/lib -L/usr/lib
> > obj/lib/VBoxOGLhostspuload.a obj/bin/VBoxOGLhostcrutil.so obj/lib/VBoxOGL2D.a
> > -lGL
> > obj/bin/VBoxRT.so obj/bin/VBoxRT.so obj/lib/VBoxREM.so obj/bin/VBoxVMM.so
> > -lXcursor -lXext -lX11
> > obj/lib/VBoxCOM.a obj/bin/VBoxXPCOM.so
> > /usr/lib/libQtCore.so /usr/lib/libQtGui.so /usr/lib/libQtOpenGL.so

Here you link libGL _after_ an archive that requires it, so it's
included. And:

> [lkundrak@localhost VirtualBox-3.1.6_OSE]$ g++
> > -o out/linux.x86/release/obj/VBoxTestOGL/VBoxTestOGL
> > out/linux.x86/release/obj/VBoxTestOGL/generic/OpenGLTestApp.o
> > -L/usr/X11R6/lib -L/usr/lib
> > -lGL
> > obj/lib/VBoxOGLhostspuload.a obj/bin/VBoxOGLhostcrutil.so obj/lib/VBoxOGL2D.a
> > obj/bin/VBoxRT.so obj/bin/VBoxRT.so obj/lib/VBoxREM.so obj/bin/VBoxVMM.so
> > -lXcursor -lXext -lX11
> > obj/lib/VBoxCOM.a obj/bin/VBoxXPCOM.so
> > /usr/lib/libQtCore.so /usr/lib/libQtGui.so /usr/lib/libQtOpenGL.so

Here you link without --as-needed, so a DT_NEEDED note for libGL is
emitted unconditionally; therefore, by the time you get to VBoxOGL2D.a,
libGL is included in the link already.

[1] - The new linker behaviour in F13 does change things. Recall that
the default used to be "--add-needed", which has since been renamed
--copy-dt-needed-entries. What this means is, when producing a dynamic
object as output, any DT_NEEDED entries in dynamic libraries mentioned
on the link line will be copied into the output. The last library in
that link line, libQtOpenGL.so, almost certainly has a DT_NEEDED entry
for libGL.so already. So, when doing --copy-dt-needed-entries, that
link line would have worked: the first mention of -lGL would have been
skipped over, but then it would have been included since libQtOpenGL had
a DT_NEEDED for it. Now, in F13, since --no-copy-dt-needed-entries is
the default, this doesn't happen; DT_NEEDED entries are only emitted for
things you really declare that you need. This is desirable; it allows
libraries to change the libraries they themselves depend on, without
necessarily requiring applications to also be recompiled.

- ajax
--
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel
 

Thread Tools




All times are GMT. The time now is 11:32 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org