frostalf / libtorrent

Automatically exported from code.google.com/p/libtorrent
0 stars 0 forks source link

can't build static binary of simple_client or client_test #142

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Follow steps to build libtorrent from here:
http://www.rasterbar.com/products/libtorrent/building.html
(I've actually tried it with the latest SVN and the latest release from here as 
well:
https://code.google.com/p/libtorrent/downloads/detail?name=libtorrent-rasterbar-
0.15.4.tar.gz&can=2&q=)  I have also tried it using autotools and BBv2, and 
with boost from the repos and built from source.
2. Try to compile a static binary for anything linking to libtorrent.

What is the expected output? What do you see instead?
A static binary.  Instead I see a variety of error messages, I believe the 
closest I have came so far was using 0.15.4, with boost from source, using bbv2:
libtorrent-rasterbar-0.15.4/examples$ bjam gcc link=static runtime-link=static 
boost=source client_testBOOST_ROOT = /home2/workspace/boost_1_40_0
OS = LINUX
...patience...
...patience...
...found 2569 targets...
...updating 1 target...
gcc.link 
bin/gcc-4.4.3/debug/boost-source/link-static/runtime-link-static/threading-multi
/client_test
/usr/bin/ld: attempted static link of dynamic object `/usr/lib/libdl.so'
collect2: ld returned 1 exit status

    "g++"  -Wl,-R -Wl,"/usr/lib"  -o "bin/gcc-4.4.3/debug/boost-source/link-static/runtime-link-static/threading-multi/client_test" -Wl,--start-group "bin/gcc-4.4.3/debug/boost-source/link-static/runtime-link-static/threading-multi/client_test.o" "../bin/gcc-4.4.3/debug/boost-source/link-static/runtime-link-static/threading-multi/libtorrent.a" "/home2/workspace/boost_1_40_0/bin.v2/libs/thread/build/gcc-4.4.3/debug/boost-source/link-static/runtime-link-static/threading-multi/libboost_thread.a" "/home2/workspace/boost_1_40_0/bin.v2/libs/filesystem/build/gcc-4.4.3/debug/boost-source/link-static/runtime-link-static/threading-multi/libboost_filesystem.a" "/home2/workspace/boost_1_40_0/bin.v2/libs/system/build/gcc-4.4.3/debug/boost-source/link-static/runtime-link-static/threading-multi/libboost_system.a" "/usr/lib/libdl.so"   -lssl -lcrypto  -lrt -Wl,--end-group -g -static -pthread -export-dynamic

...failed gcc.link 
bin/gcc-4.4.3/debug/boost-source/link-static/runtime-link-static/threading-multi
/client_test...
...failed updating 1 target...

I took that command, and modified it to the following:
libtorrent-rasterbar-0.15.4/examples$ "g++"  -Wl,-R -Wl,"/usr/lib"  -o 
"bin/gcc-4.4.3/debug/boost-source/link-static/runtime-link-static/threading-mult
i/client_test" -Wl,--start-group 
"../bin/gcc-4.4.3/debug/boost-source/link-static/runtime-link-static/threading-m
ulti/libtorrent.a" 
"/home2/workspace/boost_1_40_0/bin.v2/libs/thread/build/gcc-4.4.3/debug/boost-so
urce/link-static/runtime-link-static/threading-multi/libboost_thread.a" 
"/home2/workspace/boost_1_40_0/bin.v2/libs/filesystem/build/gcc-4.4.3/debug/boos
t-source/link-static/runtime-link-static/threading-multi/libboost_filesystem.a" 
"/home2/workspace/boost_1_40_0/bin.v2/libs/system/build/gcc-4.4.3/debug/boost-so
urce/link-static/runtime-link-static/threading-multi/libboost_system.a" 
"/usr/lib/libdl.a"   -lssl -lcrypto  -lrt -Wl,--end-group -g -static -pthread 
-export-dynamic -static-libgcc -pie ./client_test.cpp -fPIC -ltorrent_rasterbar 
-I../include/ -I../../boost_1_40_0/ -DTORRENT_DISABLE_GEO_IP
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtbeginT.o: relocation 
R_X86_64_32 against `__DTOR_END__' can not be used when making a shared object; 
recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtbeginT.o: could not read symbols: Bad 
value
collect2: ld returned 1 exit status

What version of the product are you using? On what operating system?
I've tried latest SVN (revision 5110 I believe), and also 0.15.4.  My OS is 
Ubuntu 10.04 Lucid x86_64.  gcc is version 4.4.3 (Ubuntu 4.4.3-4ubuntu5), boost 
is 1.40.0 (tried pre-compiled from repos, and from source)

Please provide any additional information below.
The 'official' commands I have used to build this from the manual include:
'bjam gcc link=static runtime-link=static boost=source'
and
'./configure --enable-static --enable-shared --disable-geoip --disable-debug 
--enable-tests --enable-examples CXXFlags="-UTORRENT_USE_I2P 
-DTORRENT_DISABLE_RESOLVE_COUNTRIES -UANSI_TERMINAL_COLORS"'
which gets me both libtorrent-rasterbar .so and .a, and I try to compile 
client_test like so:
'g++ -I./include/ -ltorrent-rasterbar -L./src/.libs/ -o client_test.amd64 
./examples/client_test.cpp -UTORRENT_USE_I2P 
-DTORRENT_DISABLE_RESOLVE_COUNTRIES -UANSI_TERMINAL_COLORS 
-DTORRENT_DISABLE_GEO_IP -static'
Without the '-static' on the end, it works perfectly, but with it it fails.

So I don't know where the problem is, but I'm hoping it's a silly little flag 
I'm missing someplace.

Original issue reported on code.google.com by moparist...@gmail.com on 24 Dec 2010 at 5:16

GoogleCodeExporter commented 9 years ago
I've done some more investigating, and if I force bjam to use my own 'custom' 
g++ that looks like this:

#!/bin/sh
/usr/bin/g++ -fPIE -pie -static -static-libgcc -m32 "$@"

(notice I am compiling a 32-bit executable now, same 64-bit host though)

Then it will actually spit out a client_test executable, unfortunately it is 
still not static.  This is the tail end of the building log that possibly 
explains why and then a run of 'file' which shows it is dynamically linked:

gcc.archive 
/home2/workspace/boost_1_40_0/bin.v2/libs/system/build/gcc-4.4.3/debug/boost-sou
rce/link-static/runtime-link-static/threading-multi/libboost_system.a
gcc.link 
bin/gcc-4.4.3/debug/boost-source/link-static/runtime-link-static/threading-multi
/client_test
../bin/gcc-4.4.3/debug/boost-source/link-static/runtime-link-static/threading-mu
lti/libtorrent.a(session_impl.o): In function 
`boost::asio::detail::socket_ops::getaddrinfo(char const*, char const*, 
addrinfo const*, addrinfo**, boost::system::error_code&)':
session_impl.cpp:(.text._ZN5boost4asio6detail10socket_ops11getaddrinfoEPKcS4_PK8
addrinfoPPS5_RNS_6system10error_codeE[boost::asio::detail::socket_ops::getaddrin
fo(char const*, char const*, addrinfo const*, addrinfo**, 
boost::system::error_code&)]+0x3e): warning: Using 'getaddrinfo' in statically 
linked applications requires at runtime the shared libraries from the glibc 
version used for linking
...updated 111 targets...

$ file 
bin/gcc-4.4.3/debug/boost-source/link-static/runtime-link-static/threading-multi
/client_test
bin/gcc-4.4.3/debug/boost-source/link-static/runtime-link-static/threading-multi
/client_test: ELF 32-bit LSB shared object, Intel 80386, version 1 (GNU/Linux), 
dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped

So is there a way to get a statically compiled binary of libtorrent and/or 
client_test?

Original comment by moparist...@gmail.com on 24 Dec 2010 at 5:51

GoogleCodeExporter commented 9 years ago
when you say "statically linked", you're not talking about linking statically 
against boost or libtorrent, you're talking about the runtime library, right?

I would expect this to work: (in libtorrent/examples):

   bjam boost=source link=static runtime-link=static boost-link=static encryption=openssl

to work. However, testing this it turns out that it will try to link statically 
against libdl.so, which doesn't have a corresponding static library. libdl is 
required by libcrypto. One simple work-around would be to use libtomcrypt or 
libgcrypt instead of openssl. The drawback is that you wouldn't get ssl 
support. But this should work:

   bjam boost=source link=static runtime-link=static boost-link=static encryption=tommath

I'm not sure how to force boost-build to link dynamically against libdl, 
regardless of the <link> property.

Original comment by arvid.no...@gmail.com on 25 Dec 2010 at 7:24