developingpld:advanceddeveloping:fixingasneeded
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
developingpld:advanceddeveloping:fixingasneeded [2006-08-07 02:41] – - some fixes SamChi | developingpld:advanceddeveloping:fixingasneeded [2007-05-27 20:51] (current) – arekm | ||
---|---|---|---|
Line 4: | Line 4: | ||
- | ==== Quick Workaround | + | ===== Quick and ugly workaround (DON'T USE IT!) ===== |
- | Put in spec file this line: | + | Put this line in '' |
- | < | ||
- | </ | ||
- | But **don' | ||
- | Why ? Because it's very stupid. If something fails to build normally | + | |
+ | < | ||
+ | </ | ||
+ | But **don't use it** unless you really need to quickly | ||
===== How --as-needed works ===== | ===== How --as-needed works ===== | ||
- | With '' | + | With '' |
- | == About positions | + | ==== Why it fails for some packages ==== |
- | Linker options are positional, and position is very important. Because it looks for missing symbols | + | In other words, if you list 10 libraries |
- | Correct | + | This normally works because if project requires libraries //A// and //B// and //A// itself lists //B// as a dependency, both //A// and //B// get pulled in even if the project itself only lists //A//. |
+ | |||
+ | Now assume that //A// is a superfluous (unneeded) dependency which gets dropped (or //A// requiring //B// is superfluous and //B// gets dropped from //A//). The symbols are no longer available. | ||
+ | |||
+ | |||
+ | |||
+ | ==== About positions ==== | ||
+ | Linker options are positional, and position is very important. It looks for missing symbols only in libraries coming after object file. | ||
+ | |||
+ | Correct | ||
< | < | ||
Line 29: | Line 38: | ||
and this generally works well. | and this generally works well. | ||
- | If there is something like that: | + | |
+ | If there is something like that: | ||
< | < | ||
Line 35: | Line 45: | ||
the library will __never__ be linked, because it's not required at the time it's checked. | the library will __never__ be linked, because it's not required at the time it's checked. | ||
- | And with something like that: | + | |
+ | And with something like that: | ||
< | < | ||
</ | </ | ||
- | library will allways | + | library will __allways__ |
==== Short examples ==== | ==== Short examples ==== | ||
- | Most of problems are with readline/ | + | Most of problems are with readline/ |
- | But some packages link with readline or ncurses while they use __only__ symbols from tinfo. | + | But some packages link with readline or ncurses while they use __only__ symbols from tinfo. //Without// '' |
For a longer example take a look at real example nr. 1. | For a longer example take a look at real example nr. 1. | ||
Line 59: | Line 70: | ||
< | < | ||
</ | </ | ||
- | it's usual 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. 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). | + | It's usual situation |
Line 73: | Line 84: | ||
- | < | + | < |
VApp.o: In function `vapp:: | VApp.o: In function `vapp:: | ||
Line 98: | Line 109: | ||
Binary file / | Binary file / | ||
</ | </ | ||
- | they are in '' | + | They are in '' |
What we get after running make in build tree: | What we get after running make in build tree: | ||
Line 104: | Line 115: | ||
- | < | + | < |
VApp.o: In function `vapp:: | VApp.o: In function `vapp:: | ||
Line 137: | Line 148: | ||
- | < | + | < |
make[1]: Leaving directory `/ | make[1]: Leaving directory `/ | ||
</ | </ | ||
- | //It worked !// | + | **It worked !** |
Line 178: | Line 189: | ||
- | < | + | < |
+ | -lgnome-keyring -lpthread | ||
- | x86_64-pld-linux-gcc -ggdb -O2 -ftree-vectorize -ftree-vectorizer-verbose=1 -march=athlon64 -mmmx -msse -msse2 -m3dnow -mfpmath=sse -Wall -Wmissing-prototypes -Wno-sign-compare | + | gcc -Wl, |
./ | ./ | ||
Line 209: | Line 221: | ||
'' | '' | ||
- | So add this one and glade to that library deps: | + | So add this one and '' |
Line 232: | Line 244: | ||
== Why was it working without --as-needed ? == | == Why was it working without --as-needed ? == | ||
- | test-source-selector binary was linked with all libraries needed by 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: | ||
+ | |||
+ | < | ||
+ | / | ||
+ | (.text+0x20): | ||
+ | collect2: ld returned 1 exit status | ||
+ | </ | ||
+ | And incorrectly linked one: | ||
+ | |||
+ | < | ||
+ | / | ||
+ | (.text+0x20): | ||
+ | / | ||
+ | / | ||
+ | [...] | ||
+ | / | ||
+ | collect2: ld returned 1 exit status | ||
+ | </ | ||
+ | **Warning: | ||
==== 3. unresolved symbols caused by incorrect order ==== | ==== 3. unresolved symbols caused by incorrect order ==== | ||
- | Two of most difficult of common problems at once, [[http:// | + | Two of most difficult of common problems at once, [[http:// |
The difficulties are: | The difficulties are: | ||
Line 255: | Line 292: | ||
- | < | + | < |
/ | / | ||
Line 262: | Line 299: | ||
collect2: ld returned 1 exit status | collect2: ld returned 1 exit status | ||
</ | </ | ||
- | function ''' | + | function ''' |
- | just take a look at my fix: | + | Just take a look at my fix: |
Line 276: | Line 313: | ||
+ | + | ||
</ | </ | ||
- | with this simple change everything works perfectly. | + | With this simple change everything works perfectly. |
developingpld/advanceddeveloping/fixingasneeded.1154911272.txt.gz · Last modified: 2006-08-07 02:41 by SamChi