Cannot compile rtorrent/libtorrent

Hello

I updated ports on my home server like I usually do: 1-2 times per year. I sometimes get problems but have so far managed to solve them. But now I have a problem, that net-p2p/rtorrent does not compile:

Code:
/bin/sh ../libtool  --tag=CXX    --mode=link clang++   -O2 -pipe -march=core2 -fstack-protector -fno-strict-aliasing
-DNDEBUG -D_THREAD_SAFE   -I/usr/local/include   -I/usr/local/include  -pthread -Wl,-rpath=/usr/lib:/usr/local/lib
-fstack-protector -o rtorrent main.o libsub_root.a  ui/libsub_ui.a  core/libsub_core.a  display/libsub_display.a
input/libsub_input.a  rpc/libsub_rpc.a  utils/libsub_utils.a -lncursesw  -L/usr/local/lib -lcurl   -L/usr/local/lib -ltorrent
libtool: link: clang++ -O2 -pipe -march=core2 -fstack-protector -fno-strict-aliasing -DNDEBUG -D_THREAD_SAFE -I/usr/local/include
-I/usr/local/include -pthread -Wl,-rpath=/usr/lib:/usr/local/lib -fstack-protector -o rtorrent main.o  libsub_root.a ui/libsub_ui.a
core/libsub_core.a display/libsub_display.a input/libsub_input.a rpc/libsub_rpc.a utils/libsub_utils.a -lncursesw -L/usr/local/lib -lcurl -ltorrent -pthread
/usr/local/lib/libtorrent.so: undefined reference to `DH_generate_key'
/usr/local/lib/libtorrent.so: undefined reference to `DH_free'
/usr/local/lib/libtorrent.so: undefined reference to `DH_size'
/usr/local/lib/libtorrent.so: undefined reference to `BN_bin2bn'
/usr/local/lib/libtorrent.so: undefined reference to `SHA1_Init'
/usr/local/lib/libtorrent.so: undefined reference to `RC4_set_key'
/usr/local/lib/libtorrent.so: undefined reference to `BN_num_bits'
/usr/local/lib/libtorrent.so: undefined reference to `DH_new'
/usr/local/lib/libtorrent.so: undefined reference to `BN_bn2bin'
/usr/local/lib/libtorrent.so: undefined reference to `SHA1_Update'
/usr/local/lib/libtorrent.so: undefined reference to `SHA1_Final'
/usr/local/lib/libtorrent.so: undefined reference to `RC4'
/usr/local/lib/libtorrent.so: undefined reference to `DH_compute_key'
/usr/local/lib/libtorrent.so: undefined reference to `BN_free'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
*** [rtorrent] Error code 1
1 error
*** [all-recursive] Error code 1
1 error
*** [all-recursive] Error code 1
1 error
*** [all] Error code 2
1 error
===> Compilation failed unexpectedly.
Try to set MAKE_JOBS_UNSAFE=yes and rebuild before reporting the failure to
the maintainer.
*** [do-build] Error code 1

Stop in /usr/ports/net-p2p/rtorrent.
*** [stage] Error code 1

Stop in /usr/ports/net-p2p/rtorrent.

System is FreeBSD 9.3:
Code:
9.3-RELEASE-p9 FreeBSD 9.3-RELEASE-p9 #0: Tue Jan 27 10:43:40 UTC 2015
root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64

What have I tried so far:

downgrading net-p2p/rtorrent, net-p2p/libtorrent and finally security/openssl to a version over from June 2015 (back then it worked for sure) - still won't compile! I did recompile openssl with all the dependencies. Since that did not work, i did try installing latest binary packages:

rtorrent-0.9.6_1.txz
libtorrent-0.13.6.txz
openssl-1.0.2_14.txz

But it did not work - when I start rtorrent, I get error message:
Code:
usr/local/lib/libtorrent.so.19: Undefined symbol "SHA1_Init"

I am at wits end! What else should I try?
 
/etc/make.conf contents are:

Code:
CPUTYPE?=core2
ENABLE_SUIDPERL=true
WITHOUT_X11=true
OPTIONS_UNSET=X11
BUILD_OPTIMIZED=true
WITH_THREADSAFE=true
NO_WARNING_PKG_INSTALL_EOL=yes
NO_WERROR=true
DEFAULT_VERSIONS+=perl5=5.20
DEFAULT_VERSIONS+=ssl=openssl
WITH_OPENSSL_PORT=yes
 
Forgot to mention, I also tried to compile on other FreeBSD 9.3 machine. Much less ports there, and rtorrent never been there. Same result, won't compile.
 
Yes, as far as I know it's a function of OpenSSL. Not all ports may be able to use the port's OpenSSL. Have you tried removing it and let the system figure it out?
 
I tried it now, did not help, still won't compile.

What I did find out comparing older and newer libtorrent library, that new one is not linked to libcrypto:

Code:
# ldd /usr/local/lib/libtorrent.so.19
/usr/local/lib/libtorrent.so.19:
        libz.so.6 => /lib/libz.so.6 (0x8012e7000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x8014fb000)
        libm.so.5 => /lib/libm.so.5 (0x801802000)
        libc.so.7 => /lib/libc.so.7 (0x80081b000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x801a23000)
# ldd /usr/local/lib/compat/pkg/libtorrent.so.14
/usr/local/lib/compat/pkg/libtorrent.so.14:
        libcrypto.so.8 => /usr/local/lib/libcrypto.so.8 (0x80134d000)
        libsigc-2.0.so.0 => /usr/local/lib/libsigc-2.0.so.0 (0x801778000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x80197e000)
        libm.so.5 => /lib/libm.so.5 (0x801c85000)
        libc.so.7 => /lib/libc.so.7 (0x80081b000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x801ea6000)
        libthr.so.3 => /lib/libthr.so.3 (0x8020b4000)
How to force it to make it to be linked to libcrypto?

I might set up a clean FreeBSD 9.3 64-bit virtual machine and try compiling there, to see if I get the same result.
 
Looking at the directories (/usr/local/lib/*) I'm guessing the latter has been linked to the port's OpenSSL. The first looks like it hasn't been linked to any SSL library.
 
net-p2p/rtorrent never explicitly links with libcrypto itself. As you found out net-p2p/libtorrent should link with libcrypto but doesn't for some reason. On my system this happens too but I'm able to build rtorrent successfully. Since package builds succeed on the FreeBSD build cluster I think some of rtorrent's dependencies links with libcrypto so the issue doesn't manifest there or on my system. You likely selected some non-default options somewhere.

Can you apply this patch to net-p2p/libtorrent and reinstall it ( make clean reinstall)? See if it links with libcrypto then ( ldd /usr/local/lib/libtorrent.so.19). If that works I think you should be able to compile net-p2p/rtorrent.
Code:
Index: Makefile
===================================================================
--- Makefile	(revision 418651)
+++ Makefile	(working copy)
@@ -19,12 +19,10 @@
 KQUEUE_DESC=	Use kqueue(2) support
 
 CONFIGURE_ARGS=	--disable-debug
-CONFIGURE_ENV=	OPENSSL_LIBS="-L${OPENSSLBASE}/lib -ssl -crypto" OPENSSL_CFLAGS="-I${OPENSSLBASE}/include"
 GNU_CONFIGURE=	yes
 INSTALL_TARGET=	install-strip
 USE_LDCONFIG=	yes
-USE_OPENSSL=	yes
-USES=		compiler:c++11-lang libtool pathfix pkgconfig
+USES=		compiler:c++11-lang libtool pathfix pkgconfig ssl
 
 IPV6_CONFIGURE_ENABLE=	ipv6
 KQUEUE_CONFIGURE_WITH=	kqueue
 
And that worked! libtorrent is now linked to libcrypto and rtorrent compiled and works too:

Code:
# ldd /usr/local/lib/libtorrent.so.19
/usr/local/lib/libtorrent.so.19:
        libz.so.6 => /lib/libz.so.6 (0x8012e7000)
        libcrypto.so.6 => /lib/libcrypto.so.6 (0x8014fb000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x8018a3000)
        libm.so.5 => /lib/libm.so.5 (0x801baa000)
        libc.so.7 => /lib/libc.so.7 (0x80081b000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x801dcb000)
I messed around with CONFIGURE_ENV before, but did not know to change USES.
 
And that worked! libtorrent is now linked to libcrypto and rtorrent compiled and works too:
Great. :)

I hope rtorrent won't crash with it. There is still the issue that it links with the base's version in /lib instead of the one in /usr/local/lib which can sometimes lead to problems when loaded libraries link to two different versions of OpenSSL. I don't think you'll run into this problem given the linker errors you had. You can check with ldd /usr/local/bin/rtorrent | grep crypto. You should only see one libcrypto line. I'll see if I can fix this.

Anyway I'll open a bug for this soon to get it fixed in the ports tree.

EDIT: Fixed it and opened PR 211223
 
Back
Top