When linking: use the -l flag or just treat the archives as input

I'm having trouble linking the stxxl static library in a shared library, as stated in my question Linking a static library to Boost Python (shared library) - Import error

The team I used was

g++ -Wall -pthread -march=i686 -I/home/zenna/Downloads/stxxl-1.3.0/include -include stxxl/bits/defines.h -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -I /home/zenna/local/include/ -I /usr/include/python2.6/ -fPIC -c partition.cpp -o obj/Partition_wrap.o

and link:

g++  -shared -lboost_python -L/home/zenna/local/lib/ -L/home/zenna/Downloads/stxxl-1.3.0/lib/bk/ -Wall -pthread -L/home/zenna/Downloads/stxxl-1.3.0/lib -lstxxl -o lib/fast_parts.so obj/Partition_wrap.o 

Using nm, I found that the missing characters were in the final output library of shared objects, but were of type “U” for undefined.

Then I changed the bind command to not only use -lstxxl, but also add the entire archive file as another input to the linker

so the new team was (difference at the end)

++ -shared -lboost_python -L/home/zenna/local/lib/-L/home/zenna/Downloads/stxxl-1.3.0/lib/bk/-Wall -pthread -L/home/zenna//stxxl-1.3.0/lib -lstxxl -o lib/fast_parts.so obj/Partition_wrap.o obj/libstxxl.a

, .

-l- undefined?

+3
1

, , -lstxxl . libstxxl.a , undefined . obj/Partition_wrap.o , undefined.

man ld

ld -o/lib/crt0.o hello.o -lc

ld output "/lib/crt0.o" "hello.o" "libc.a",         . (. -l .)

ld . , ,         -l -T, , ,         .

- , . ,         , , .

-l namespec

, , .            , undefined , ,             . undefined , ,             .

, .

+1

Source: https://habr.com/ru/post/1760536/


All Articles