PLDWWW: DevelopingPLD/AdvancedDeveloping/FixingAsNeeded

sparky sparky at pld-linux.org
Mon Aug 7 16:27:39 CEST 2006


Author: sparky   Date: Mon Aug  7 14:27:39 2006 GMT
Module: PLDWWW   URL: http://www.pld-linux.org/DevelopingPLD/AdvancedDeveloping/FixingAsNeeded
---- Log message:
- some fixes, gcc <library> trick

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

---- Diffs:

================================================================
  
  
  == How --as-needed works ==
- With {{{--as-needed}}} enabled only libraries which contain symbols required by
+ With {{{--as-needed}}} enabled, only libraries containing symbols required by
  __object files__ are linked.
  
  ===== About positions =====
  Linker options are positional, and position is very important.
- Because it looks for missing symbols only in libraries coming after object file.
+ It looks for missing symbols only in libraries coming after object file.
  
- Correct ones are:
+ Correct positions are:
  {{{
  $ gcc $(LDFLAGS) -o $@ $(OBJECTS) $(LIBS)
  }}}
@@ -74, +74 @@

  {{{
  $ gcc -Wl,--as-needed -o executable <objects.o> -l2 -l1
  }}}
- it's usual when object files require only library 2, and -l1 is required by -l2.
+ It's usual situation when object files require only library 2, and ''-l1'' is required by ''-l2''.
- As I said linker only checks 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
+ Normally it is easy to fix it, simply make sure while linking ''-l2'' it is
- linked to -l1 (take a look at the second real example).
+ linked to ''-l1'' (take a look at the second real example).
  
  
  
@@ -95, +95 @@

  With {{{-Wl,--as-needed}}} enabled it stops on something like this:
  
  {{{
- x86_64-pld-linux-g++ -DNOMMGR -Wall -DGAMEDATADIR=\"/usr/share/xmoto\"  -ggdb -O2 -Wl,--as-needed -o xmoto-edit  BuiltInFont.o [...object files...] Packager.o -lGL -lcurl -lode -llualib50 -llua50 -lSDL_mixer -lbz2 -lz -lpng -ljpeg
+ x86_64-pld-linux-g++ -Wl,--as-needed -o xmoto-edit BuiltInFont.o [...object files...] Packager.o -lGL -lcurl -lode -llualib50 -llua50 -lSDL_mixer -lbz2 -lz -lpng -ljpeg
  
  VApp.o: In function `vapp::App::getRealTime()':
  src/VApp.cpp:287: undefined reference to `SDL_GetTicks'
@@ -122, +122 @@

  Binary file /usr/lib64/libSDL.so matches
  }}}
  
- they are in {{{-lSDL}}}, but binary does not link with {{{-lSDL}}};
+ They are in {{{-lSDL}}}, but binary does not link with {{{-lSDL}}}.
- edit Makefile by hand and add {{{-lSDL}}} at the same place {{{-lSDL_mixer}}} is:
+ Edit Makefile by hand and add {{{-lSDL}}} at the same place {{{-lSDL_mixer}}} is:
  {{{LIBS = -lcurl -lode -llualib50 -llua50 -lSDL_mixer -lSDL -lbz2 -lz -lpng -ljpeg}}}
  
  What we get after running make in build tree:
  
  {{{
- x86_64-pld-linux-g++ -DNOMMGR -Wall -DGAMEDATADIR=\"/usr/share/xmoto\" -ggdb -O2 -Wl,--as-needed -o xmoto-edit BuiltInFont.o [...object files...] Packager.o  -lcurl -lode -llualib50 -llua50 -lSDL_mixer -lSDL -lbz2 -lz -lpng -ljpeg
+ x86_64-pld-linux-g++ -Wl,--as-needed -o xmoto-edit BuiltInFont.o [...object files...] Packager.o -lcurl -lode -llualib50 -llua50 -lSDL_mixer -lSDL -lbz2 -lz -lpng -ljpeg
  
  VApp.o: In function `vapp::App::grabScreen()':
  src/VApp.cpp:667: undefined reference to `glReadBuffer'
@@ -164, +164 @@

  Anyway, lets run make, and what we get ?
  
  {{{
- x86_64-pld-linux-g++ -DNOMMGR -Wall -DGAMEDATADIR=\"/usr/share/xmoto\"  -ggdb -O2 -Wl,--as-needed -o xmoto-edit  BuiltInFont.o [...object files...] Packager.o  -lcurl -lode -llualib50 -llua50 -lSDL_mixer -lSDL -lGL -lbz2 -lz -lpng -ljpeg
+ x86_64-pld-linux-g++ -Wl,--as-needed -o xmoto-edit BuiltInFont.o [...object files...] Packager.o -lcurl -lode -llualib50 -llua50 -lSDL_mixer -lSDL -lGL -lbz2 -lz -lpng -ljpeg
  
  make[1]: Leaving directory `/home/users/sparky/rpm/BUILD/xmoto-0.2.0'
  }}}
  
- ''It worked !''
+ '''It worked !'''
  
  
  ===== Why was it working without --as-needed ? =====
@@ -213, +213 @@

  Compilation stops at this place:
  
  {{{
- /bin/sh ../libtool --tag=CC --mode=link x86_64-pld-linux-gcc -ggdb -O2 -Wall  -Wl,--as-needed -o test-source-selector  test-source-selector.o libedataserverui-1.2.la ../libedataserver/libedataserver-1.2.la -pthread -lglade-2.0 [...many -l libraries...]
+ /bin/sh ../libtool --tag=CC --mode=link x86_64-pld-linux-gcc -Wl,--as-needed -o test-source-selector  test-source-selector.o libedataserverui-1.2.la ../libedataserver/libedataserver-1.2.la -pthread -lglade-2.0 [...many -l libraries...]
  -lgnome-keyring -lpthread
  
- x86_64-pld-linux-gcc -ggdb -O2 -Wall -Wl,--as-needed -o .libs/test-source-selector test-source-selector.o -pthread ./.libs/libedataserverui-1.2.so [many, many .so and -l libraries] -lpthread
+ x86_64-pld-linux-gcc -Wl,--as-needed -o .libs/test-source-selector test-source-selector.o -pthread ./.libs/libedataserverui-1.2.so [...many, many .so and -l libraries...] -lpthread
  
  ./.libs/libedataserverui-1.2.so: undefined reference to `glade_xml_new'
  ./.libs/libedataserverui-1.2.so: undefined reference to `gnome_keyring_find_items_sync'
@@ -249, +249 @@

  
  {{{GNOME_KEYRING_LIBS = -lgnome-keyring -lglib-2.0}}}
  
- So add this one and glade to that library deps:
+ So add this one and {{{-lglade-2.0}}} to that library deps:
  
  {{{
  libedataserverui_1_2_la_LIBADD = \
@@ -277, +277 @@

  }}}
  
  ===== Why was it working without --as-needed ? =====
- test-source-selector binary was linked with all libraries needed by
+ {{{test-source-selector}}} binary was linked with all libraries needed by
  libedataserverui-1.2.so, and the binary was the one who provided
  missing symbols to libedataserverui-1.2.so
  
  
  
+ 
+ ==== What if broken library comes from other package ? ====
+ 
+ You can check manually does library has all required symbols, simply running
+ 'gcc ''library'' ', like this:
+ 
+ This is an example of correctly linked library:
+ {{{
+ $ gcc /usr/lib64/liblftp-tasks.so.0.0.0
+ /usr/lib64/gcc/x86_64-pld-linux/4.1.2/../../../../lib64/crt1.o: In function `_start':
+ (.text+0x20): undefined reference to `main'
+ collect2: ld returned 1 exit status
+ }}}
+ 
+ 
+ And inclrrectly linked:
+ {{{
+ $ gcc /usr/lib64/liblftp-jobs.so.0.0.0 
+ /usr/lib64/gcc/x86_64-pld-linux/4.1.2/../../../../lib64/crt1.o: In function `_start':
+ (.text+0x20): undefined reference to `main'
+ /usr/lib64/liblftp-jobs.so.0.0.0: undefined reference to `StringSet::Remove(int)'
+ /usr/lib64/liblftp-jobs.so.0.0.0: undefined reference to `Buffer::Format(char const*, ...)'
+ [...]
+ /usr/lib64/liblftp-jobs.so.0.0.0: undefined reference to `SMTask::SuspendSlave()'
+ collect2: ld returned 1 exit status
+ }}}
  
  
  


More information about the pld-cvs-commit mailing list