I'm compiling an executable called "interrogate" with:
g++ -o built/bin/interrogate -Lbuilt/lib -Lbuilt/tmp -L/usr/X11R6/lib \
built/tmp/interrogate_composite1.o built/tmp/interrogate_composite2.o \
-lp3cppParser -lp3dtool -lp3dtoolconfig -lp3pystub -pthread -ldl
After the compilation, when i try to execute the executable:
$ LD_LIBRARY_PATH=built/lib built/bin/interrogate
built/bin/interrogate: symbol lookup error: built/lib/libp3dtool.so.1.8: undefined symbol: _Py_NoneStruct
This symbol is provided by the libp3pystub.so, but the interrogate executable doesn't have any reference to this library (I did used the -lp3pystub):
$ LD_LIBRARY_PATH=built/lib ldd built/bin/interrogate
linux-vdso.so.1 => (0x00007fff2016a000)
libp3dtool.so.1.8 => built/lib/libp3dtool.so.1.8 (0x00007f498d57a000)
libp3dtoolconfig.so.1.8 => built/lib/libp3dtoolconfig.so.1.8 (0x00007f498d51b000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f498d1f2000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f498cfdc000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f498cdbf000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f498c9ff000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f498c7fb000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f498c4ff000)
/lib64/ld-linux-x86-64.so.2 (0x00007f498d5bc000)
If i manually load the libp3pystub.so, the executable works:
$ LD_PRELOAD=built/lib/libp3pystub.so LD_LIBRARY_PATH=built/lib built/bin/interrogate
Usage:
interrogate [opts] file.C [file.C ...]
interrogate -h
My question is: why the library i've added with -lp3pystub is not referenced by the interrogate executable?
I actually find the answer myself. I was compiling on Ubuntu, and they added a default optimization flags: -Wl,--as-needed. This optimization check if no symbol from the libraries passed with -l are used in the main executable, they will be removed.
And that's where my error was: _Py_NoneStruct is not directly used by interrogate, but by another shared library. So i must manually specify that the p3pystub is needed.
One possible fix would be:
$ g++ -o built/bin/interrogate -Lbuilt/lib -Lbuilt/tmp -L/usr/X11R6/lib \
built/tmp/interrogate_composite1.o built/tmp/interrogate_composite2.o \
-Wl,--no-as-needed -lp3cppParser -lp3dtool -lp3dtoolconfig -lp3pystub \
-pthread -ldl
And then i correctly got the library in the ldd output:
$ LD_LIBRARY_PATH=built/lib ldd built/bin/interrogate
linux-vdso.so.1 => (0x00007fff0edff000)
libp3dtool.so.1.8 => built/lib/libp3dtool.so.1.8 (0x00007fa1c36be000)
libp3dtoolconfig.so.1.8 => built/lib/libp3dtoolconfig.so.1.8 (0x00007fa1c365f000)
>>> libp3pystub.so.1.8 => built/lib/libp3pystub.so.1.8 (0x00007fa1c3658000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa1c342f000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa1c312c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa1c2e2f000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa1c2c19000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa1c29fc000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa1c263c000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa1c3700000)
Reference:
https://wiki.ubuntu.com/NattyNarwhal/ToolchainTransition
Related
I'm trying to install ffmpeg with libvpx & libx264 on my vps. Centos07. I've followed these instructions https://trac.ffmpeg.org/wiki/CompilationGuide/Centos to the T.
Now when I try to run
cd ~/ffmpeg; ./configure --enable-libvpx --enable-gpl --enable-libx264
it returns
-bash: ./configure: No such file or directory
When I try ffmpeg -v
ffmpeg: error while loading shared libraries: libx264.so.148: cannot open shared object file: No such file or directory
and ldd $(which ffmpeg) returns
root#host [~/ffmpeg_sources]# ldd $(which ffmpeg)
linux-vdso.so.1 => (0x00007fff4fb86000)
libxcb.so.1 => /lib64/libxcb.so.1 (0x00007f4972e27000)
libxcb-shm.so.0 => /lib64/libxcb-shm.so.0 (0x00007f4972c23000)
libxcb-xfixes.so.0 => /lib64/libxcb-xfixes.so.0 (0x00007f4972a1a000)
libxcb-shape.so.0 => /lib64/libxcb-shape.so.0 (0x00007f4972816000)
libx264.so.148 => not found
libm.so.6 => /lib64/libm.so.6 (0x00007f4972513000)
liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f49722ee000)
libbz2.so.1 => /lib64/libbz2.so.1 (0x00007f49720de000)
libz.so.1 => /lib64/libz.so.1 (0x00007f4971ec7000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f4971cab000)
libc.so.6 => /lib64/libc.so.6 (0x00007f49718e9000)
libXau.so.6 => /lib64/libXau.so.6 (0x00007f49716e4000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4973056000)
I've followed all the instructions exactly - is there something I'm missing?
[poster#localhost lib]$ ldd libavfilter.so
linux-vdso.so.1 => (0x00007ffc6bbd0000)
libswscale.so.4 => not found
libpostproc.so.54 => not found
libavformat.so.57 => not found
libavcodec.so.57 => not found
libswresample.so.2 => not found
libavutil.so.55 => not found
libm.so.6 => /lib64/libm.so.6 (0x00007fc796d79000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fc796b5c000)
libc.so.6 => /lib64/libc.so.6 (0x00007fc79679b000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc79742b000)
[poster#localhost lib]$ ldd libswscale.so
linux-vdso.so.1 => (0x00007ffe29572000)
libavutil.so.55 => not found
libm.so.6 => /lib64/libm.so.6 (0x00007f4cfdea3000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f4cfdc87000)
libc.so.6 => /lib64/libc.so.6 (0x00007f4cfd8c6000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4cfe442000)
All of them are like that.
I'm a newb and don't know how to solve this. They're right next to each other.
Any suggestion is appreciated. Thank you.
I suffered the same. Setting and exporting the LD_LIBRARY_PATH made ldd find the other .so-files.
In my case I had put libavfilter.so in folder /usr/local/lib that was already listen in /etc/ld.so.conf but still didn't work without this:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
Recompile ffmpeg library with rpath like that:
LDFLAGS="-L. -Wl,-rpath,." ./configure --prefix... your ffmpeg configure options.
How can I use bash to retrieve lib directory? For example: /usr/lib or /usr/lib64?
Edit
I'm packaging an RPM which copies some files to %{_libdir}. So I'd like to know the path to lib directory… I can use if [ -f "path-to-my-file" ]; then ... but I wonder if there is a command line?
ldd - print shared library dependencies
$ ldd /bin/ls
linux-vdso.so.1 => (0x00007fffbeecc000)
libselinux.so.1 => /lib/libselinux.so.1 (0x00007fa9aa630000)
librt.so.1 => /lib/librt.so.1 (0x00007fa9aa428000)
libacl.so.1 => /lib/libacl.so.1 (0x00007fa9aa220000)
libc.so.6 => /lib/libc.so.6 (0x00007fa9a9ebe000)
libdl.so.2 => /lib/libdl.so.2 (0x00007fa9a9cba000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa9aa868000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007fa9a9a9d000)
libattr.so.1 => /lib/libattr.so.1 (0x00007fa9a9899000)
cat /etc/ld.so.conf /etc/ld.so.conf.d/*
Will show you where the linker looks for libraries by default.
I wrote a code for which I have a Makefile like this:
CC=gcc
CXX=g++
DEBUG=-g
COMPILER=${CXX}
#INCLUDE= -I Re2/ -I Re2/re2/
#WARN=-Wall
spambin: main.cpp Mail.o trie.o Spambin.o config.o getdns.o
${COMPILER} ${DEBUG} ${WARN} -o spambin main.cpp Mail.o trie.o Spambin.o config.o getdns.o /usr/lib/libre2.so
trie.o: trie.cpp
${COMPILER} ${DEBUG} ${WARN} -c trie.cpp ${INCLUDE}
Mail.o: Mail.cpp
${COMPILER} ${DEBUG} ${WARN} -c Mail.cpp ${INCLUDE}
config.o: config.cpp
${COMPILER} ${DEBUG} ${WARN} -c config.cpp ${INCLUDE}
Spambin.o: Spambin.cpp
${COMPILER} ${DEBUG} ${WARN} -c Spambin.cpp ${INCLUDE}
getdns.o: getdns.c
${CC} ${DEBUG} ${WARN} -c getdns.c ${INCLUDE}
clean:
rm -f *.o
The issue I'm facing is that I want my code to directly pick the /usr/lib/libre2.so.
Doing ldd on the final output binary gives:
linux-gate.so.1 => (0x00693000)
libre2.so.0 => /usr/lib/libre2.so.0 (0x00159000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x004f4000)
libm.so.6 => /lib/libm.so.6 (0x00ce8000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x002b8000)
libc.so.6 => /lib/libc.so.6 (0x00b83000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00d13000)
/lib/ld-linux.so.2 (0x00b64000)
But when I move this file to live servers and do ldd on the binary, the result is:
linux-gate.so.1 => (0x0018b000)
libre2.so.0 => /usr/local/lib/libre2.so.0 (0x00b89000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x0040f000)
libm.so.6 => /lib/libm.so.6 (0x00ad2000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00c5e000)
libc.so.6 => /lib/libc.so.6 (0x0096c000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00ab9000)
/lib/ld-linux.so.2 (0x00949000)
The binary path is /usr/local/lib/libre2.so.0.
Is there any way we can force compiler to pick the .so file from our preferred path?
Yes, there is a way: you can specify full path to the shared library when linking,e.g.:
Let my library is: libtest2.so (it is in /projects/tests/test_so)
Let my main program cpp file is: main.cpp
Then:
g++ main.cpp -o test /projects/tests/test_so/libtest2.so
Produces binary test which has embedded absolute path /projects/tests/test_so in it. No matter where you move the test binary it will always look for /projects/tests/test_so/libtest2.so
Alternatively you may look at -rpath switch that you can use with gcc (actually it is a linker switch),e.g:
gcc -Wl,-rpath,'<path-to-lib-directory>'
But this approach may cause your program to look also for other shared libraries in <path-to-lib-directory> which may not be exactly what you want.
I'm having trouble getting a boost program to compile. The example I'm trying to compile is here: http://rosettacode.org/wiki/Web_scraping#C.2B.2B
This is what happens when I try to compile:
% g++ -Wall test.c -lboost_regex -lboost_system -lboost_thread
/tmp/ccJSxOji.o: In function `boost::exception_detail::error_info_injector<std::length_error>::error_info_injector(boost::exception_detail::error_info_injector<std::length_error> const&)':
test.c:(.text._ZN5boost16exception_detail19error_info_injectorISt12length_errorEC2ERKS3_[_ZN5boost16exception_detail19error_info_injectorISt12length_errorEC5ERKS3_]+0x53): undefined reference to `std::length_error::~length_error()'
/tmp/ccJSxOji.o: In function `boost::exception_detail::error_info_injector<std::length_error>::~error_info_injector()':
test.c:(.text._ZN5boost16exception_detail19error_info_injectorISt12length_errorED2Ev[_ZN5boost16exception_detail19error_info_injectorISt12length_errorED5Ev]+0x2e): undefined reference to `std::length_error::~length_error()'
collect2: ld returned 1 exit status
I think I've narrowed the problem down to this line:
boost::asio::streambuf response ;
I'm using gcc 4.6.0, linux of course:
% gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-linux-gnu/4.6.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: /build/src/gcc-4.6-20110429/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --enable-gnu-unique-object --enable-linker-build-id --with-ppl --enable-cloog-backend=isl --enable-lto --enable-gold --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold --disable-multilib --disable-libstdcxx-pch --enable-checking=release
Thread model: posix
gcc version 4.6.0 20110429 (prerelease) (GCC)
Possibly related thread:
Code using boost::asio::streambuf causes segfault
I hate to answer my own question, but as it turns out, I was bitten by this: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found
I did some more digging:
% ldd /usr/lib/libboost_regex.so
/usr/lib/libboost_regex.so: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by /usr/lib/libboost_regex.so)
linux-gate.so.1 => (0xb77b3000)
libicuuc.so.46 => /usr/lib/libicuuc.so.46 (0xb7553000)
libicui18n.so.46 => /usr/lib/libicui18n.so.46 (0xb7389000)
libicudata.so.46 => /usr/lib/libicudata.so.46 (0xb650a000)
librt.so.1 => /lib/librt.so.1 (0xb6501000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb6412000)
libm.so.6 => /lib/libm.so.6 (0xb63e8000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0xb63cc000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb63b1000)
libc.so.6 => /lib/libc.so.6 (0xb624b000)
libdl.so.2 => /lib/libdl.so.2 (0xb6246000)
/lib/ld-linux.so.2 (0xb77b4000)
% ldd /usr/lib/libboost_date_time.so
/usr/lib/libboost_date_time.so: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by /usr/lib/libboost_date_time.so)
linux-gate.so.1 => (0xb78cf000)
librt.so.1 => /lib/librt.so.1 (0xb788f000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb77a1000)
libm.so.6 => /lib/libm.so.6 (0xb7777000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0xb775b000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb773f000)
libc.so.6 => /lib/libc.so.6 (0xb75d9000)
/lib/ld-linux.so.2 (0xb78d0000)
In sum, my gcc-libs were out of date. To fix it, I did:
# pacman -Q -o /usr/lib/libstdc++.so.6
/usr/lib/libstdc++.so.6 is owned by gcc-libs 4.6.0-5
# pacman -S gcc-libs
Thanks to everyone who commented, you got me thinking in the right direction.