PLDWWW: DevelopingPLD/AdvancedDeveloping/FixingAsNeeded

sparky sparky at pld-linux.org
Mon Aug 7 02:41:14 CEST 2006


Author: sparky   Date: Mon Aug  7 00:41:14 2006 GMT
Module: PLDWWW   URL: http://www.pld-linux.org/DevelopingPLD/AdvancedDeveloping/FixingAsNeeded
---- Log message:
- some fixes

---- Page affected: DevelopingPLD/AdvancedDeveloping/FixingAsNeeded

---- Diffs:

================================================================
  {{{
  %devine filterout_ld -Wl,--as-needed
  }}}
- But '''don't use it''' unless you realy need.
+ But '''don't use it''' unless you really need.
  
  Why ? Because it's very stupid. If something fails to build normally
  it's a sign {{{--as-needed}}} did well it's job and disabled unneeded
@@ -22, +22 @@

  
  ===== About positions =====
  Linker options are positional, and position is very important.
+ Because it looks for missing symbols only in libraries coming after object file.
  
  Correct ones are:
  {{{
@@ -46, +47 @@

  === Short examples ===
  
  Most of problems are with readline/ncurses and tinfo, and it's nice
- example:
- tinfo is required by both readline and ncurses, and both are linked with
+ example: tinfo is required by both readline and ncurses, and both
- this library (now, when I've fixed readline).
+ are linked with this library (now, when I've
+ [http://cvs.pld-linux.org/cgi-bin/cvsweb/SOURCES/readline-shared.patch?r1=1.6&r2=1.7 fixed readline];).
  
  But some packages link with readline or ncurses while they use __only__
  symbols from tinfo. 
  ''Without'' {{{--as-needed}}} those executables work because
- they are linked with tinfo from readline/ncurses libraries. 
+ they are linked with tinfo from readline/ncurses library. 
+ ''With'' {{{--as-needed}}} it will not work, because readline/ncurses
+ contain no symbols required by executable
- ''With'' {{{--as-needed}}} it
- will not work, because readline/ncurses contain no symbols required
- by executable
  so they are not linked, it's dependencies naturally are neither linked.
- So there is a need to pass {{{-ltinfo}}}. If it requires only symbols from
+ Thats why there is a need to pass {{{-ltinfo}}}. If it requires only symbols from
- tinfo it's ok to {{{s/ncurses/tinfo/}}}. But if it realy requires
+ tinfo it's ok to {{{s/ncurses/tinfo/}}}. But if it really requires
  readline/ncurses but
  there is some executable (or ./configure) which requires only tinfo both
  {{{-lreadline}}}/{{{-lncurses}}} and {{{-ltinfo}}} should be passed.
  
+ For a longer example take a look at real example nr. 1.
+ 
  ----
  
  Other common problem is when package produces some shared libraries
@@ -72, +74 @@

  {{{
  $ gcc -Wl,--as-needed -o executable <objects.o> -l2 -l1
  }}}
- and normally objects require only library 2, and -l1 is required by -l2.
+ it's usual when object files require only library 2, and -l1 is required by -l2.
- As I said it checks only for symbols from objects, so -l1 is not linked.
+ As I said linker only checks for symbols from objects, so -l1 is not linked.
  Normally it is easy to fix it, simply make sure while linking -l2 it is
- linked to -l1.
+ linked to -l1 (take a look at the second real example).
  
  
  
  
- == Examples ==
+ == Real examples ==
  
  === 1. unresolved symbols in executable ===
- xmoto
+ 
+ Very common situation,
+ [http://cvs.pld-linux.org/cgi-bin/cvsweb/SPECS/xmoto.spec?rev=HEAD xmoto.spec].
+ Actually, it's nothing new. Every linking behaves this way if some library
+ is missing.
  
  
  With {{{-Wl,--as-needed}}} enabled it stops on something like this:
@@ -137, +143 @@

  collect2: ld returned 1 exit status
  }}}
  
+ 
  Same story:
  
  {{{
@@ -146, +153 @@

  
  {{{LIBS = -lcurl -lode -llualib50 -llua50 -lSDL_mixer -lSDL -lGL -lbz2 -lz -lpng -ljpeg}}}
  
- But take a look at spec file, -lGL thing was fixed there already:
+ But [http://cvs.pld-linux.org/cgi-bin/cvsweb/SPECS/xmoto.spec?rev=1.21 take a look at spec file], {{{-lGL}}} thing was fixed there already:
  
  {{{
  %{__make} \
@@ -166, +173 @@

  
  
  ===== Why was it working without --as-needed ? =====
- Answer is realy easy: libSDL is required by SDL_mixer:
+ Answer is really easy: libSDL is required by SDL_mixer:
  
  {{{
  $ ldd /usr/lib64/libSDL_mixer-1.2.so.0.2.4 | grep SDL
          libSDL-1.2.so.0 => /usr/lib64/libSDL-1.2.so.0 (0x00002ab425307000)
  }}}
  
- but xmoto-edit contains no SDL_mixer symbols, that's why xmoto-edit
+ but xmoto-edit contains no SDL_mixer symbols, that's why it
- wasn't linked with SDL_mixer, and nothing provided SDL library.
+ wasn't linked with SDL_mixer, and there was nothing providing SDL library.
  
  
- Can you see now why was it so stupid to disable {{{--as-needed}}} ? It worked
+ Can you see now why was it stupid to disable {{{--as-needed}}} ? It worked
  just perfectly disabling unneeded library !
  
  
@@ -188, +195 @@

  	LIBS="-lSDL -lGL"
  }}}
  
+ or patching configure.in, and the result is:
- or patching configure.in
- and the result is:
  
- Wrote: /home/users/sparky/rpm/RPMS/xmoto-0.2.0-2.x86_64.rpm
+ {{{Wrote: /home/users/sparky/rpm/RPMS/xmoto-0.2.0-2.x86_64.rpm}}}
  
  
  
@@ -201, +207 @@

  === 2. unresolved symbols in library while linking executable ===
  
  That's the most common and a little more difficult case,
- evolution-data-server:
+ [http://cvs.pld-linux.org/cgi-bin/cvsweb/SPECS/evolution-data-server.spec?rev=HEAD evolution-data-server]:
  
  
  Compilation stops at this place:
@@ -280, +286 @@

  
  
  
- === 3. ===
+ === 3. unresolved symbols caused by incorrect order ===
- Two of most difficult of common problems at one, evolution.spec:
+ Two of most difficult of common problems at once, 
+ [http://cvs.pld-linux.org/cgi-bin/cvsweb/SPECS/evolution.spec?rev=HEAD evolution.spec]:
  
  The difficulties are:
   1. it appears in configure, what may be difficult to fix and difficult to find what the real problem is
@@ -324, +331 @@

  +	LIBS="$LIBS_save"
  }}}
  
- with this simple change everything works perfectly
+ with this simple change everything works perfectly.
  


More information about the pld-cvs-commit mailing list