Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fail using alpine linux (boost unresolved reference) #477

Closed
Toilal opened this issue Feb 14, 2016 · 12 comments
Closed

Build fail using alpine linux (boost unresolved reference) #477

Toilal opened this issue Feb 14, 2016 · 12 comments

Comments

@Toilal
Copy link

Toilal commented Feb 14, 2016

I'm trying to build libtorrent under alpine linux, but i'm stuck with an issue related to boost dependency linking. boost was installed through the OS package manager (apk), and I can list libboost_*.so files in /usr/lib directory.

I run autotool.sh, and then ./configure, but it fails at checking boost libraries.

Checking for boost libraries:
checking for boostlib >= 1.36... yes
checking whether the Boost::System library is available... yes
checking for exit in -lboost_system-mt... no
checking for exit in -lboost_system-mt... (cached) no
checking for exit in -lboost_system-mt... (cached) no
checking for exit in -lboost_system... no
checking for exit in -lboost_system... (cached) no
checking for exit in -lboost_system... (cached) no
configure: error: Could not link against boost_system !

config.log shows undefined reference errors.

/usr/lib/libboost_system.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/usr/lib/libboost_system.so: undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/usr/lib/libboost_system.so: undefined reference to `operator delete(void*)'
/usr/lib/libboost_system.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/lib/libboost_system.so: undefined reference to `std::__throw_logic_error(char const*)'
/usr/lib/libboost_system.so: undefined reference to `vtable for __cxxabiv1::__class_type_info'
/usr/lib/libboost_system.so: undefined reference to `__cxa_guard_release'
/usr/lib/libboost_system.so: undefined reference to `__cxa_guard_acquire'

Any idea ?

@arvidn
Copy link
Owner

arvidn commented Feb 14, 2016

It looks like perhaps you're linking against a c++11 build of boost without building ok torrent as c++11

@Toilal
Copy link
Author

Toilal commented Feb 14, 2016

It seems to be something like this, you're right. I've read many posts related to changes with gcc5, bringing C++11 as default ABI, with options like -D_GLIBCXX_USE_CXX11_ABI, but still no luck ... (Sorry, i'm a bit noob with native stuff ...)

@ssiloti
Copy link
Collaborator

ssiloti commented Feb 14, 2016

try adding -std=c++11 to your CXXFLAGS

@Toilal
Copy link
Author

Toilal commented Feb 14, 2016

I've already tried this, but it doesn't fix the problem. I past more logs, maybe it will help ...

configure:17168: checking whether the Boost::System library is available
configure:17192: g++ -c -g -O2 -ftemplate-depth=120  -I/usr/include conftest.cpp >&5
configure:17192: $? = 0
configure:17207: result: yes
configure:17222: checking for exit in -lboost_system-mt
configure:17247: gcc -o conftest  -g -O2  -I/usr/include  -L/usr/lib conftest.c -lboost_system-mt  -lpthread   >&5
conftest.c:33:6: warning: conflicting types for built-in function 'exit'
 char exit ();
      ^
/usr/lib/libboost_system-mt.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/usr/lib/libboost_system-mt.so: undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/usr/lib/libboost_system-mt.so: undefined reference to `operator delete(void*)'
/usr/lib/libboost_system-mt.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/lib/libboost_system-mt.so: undefined reference to `std::__throw_logic_error(char const*)'
/usr/lib/libboost_system-mt.so: undefined reference to `vtable for __cxxabiv1::__class_type_info'
/usr/lib/libboost_system-mt.so: undefined reference to `__cxa_guard_release'
/usr/lib/libboost_system-mt.so: undefined reference to `__cxa_guard_acquire'
collect2: error: ld returned 1 exit status
configure:17247: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "libtorrent-rasterbar"
| #define PACKAGE_TARNAME "libtorrent-rasterbar"
| #define PACKAGE_VERSION "1.0.8"
| #define PACKAGE_STRING "libtorrent-rasterbar 1.0.8"
| #define PACKAGE_BUGREPORT "arvid@libtorrent.org"
| #define PACKAGE_URL "http://www.libtorrent.org"
| #define PACKAGE "libtorrent-rasterbar"
| #define VERSION "1.0.8"
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_DLFCN_H 1
| #define LT_OBJDIR ".libs/"
| #define HAVE_PTHREAD 1
| #define HAVE_BOOST /**/
| #define HAVE_BOOST_SYSTEM 1
| /* end confdefs.h.  */
|
| /* Override any GCC internal prototype to avoid an error.
|    Use char because int might match the return type of a GCC
|    builtin and then its argument prototype would still apply.  */
| #ifdef __cplusplus
| extern "C"
| #endif
| char exit ();
| int
| main ()
| {
| return exit ();
|   ;
|   return 0;
| }
configure:17257: result: no
configure:17222: checking for exit in -lboost_system-mt
configure:17257: result: no/usr/lib/libboost_system.so: undefined reference to `std::__throw_logic_error(char const*)'
/usr/lib/libboost_system.so: undefined reference to `vtable for __cxxabiv1::__class_type_info'
/usr/lib/libboost_system.so: undefined reference to `__cxa_guard_release'
/usr/lib/libboost_system.so: undefined reference to `__cxa_guard_acquire'
collect2: error: ld returned 1 exit status
configure:17247: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "libtorrent-rasterbar"
| #define PACKAGE_TARNAME "libtorrent-rasterbar"
| #define PACKAGE_VERSION "1.0.8"
| #define PACKAGE_STRING "libtorrent-rasterbar 1.0.8"
| #define PACKAGE_BUGREPORT "arvid@libtorrent.org"
| #define PACKAGE_URL "http://www.libtorrent.org"
| #define PACKAGE "libtorrent-rasterbar"
| #define VERSION "1.0.8"
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_DLFCN_H 1
| #define LT_OBJDIR ".libs/"
| #define HAVE_PTHREAD 1
| #define HAVE_BOOST /**/
| #define HAVE_BOOST_SYSTEM 1
| /* end confdefs.h.  */
|
| /* Override any GCC internal prototype to avoid an error.
|    Use char because int might match the return type of a GCC
|    builtin and then its argument prototype would still apply.  */
| #ifdef __cplusplus
| extern "C"
| #endif
| char exit ();
| int
| main ()
| {
| return exit ();
|   ;
|   return 0;
| }
configure:17257: result: no
configure:17222: checking for exit in -lboost_system
configure:17257: result: no
configure:17222: checking for exit in -lboost_system

configure:17222: checking for exit in -lboost_system-mt
configure:17257: result: no
configure:17222: checking for exit in -lboost_system
configure:17247: gcc -o conftest  -g -O2  -I/usr/include  -L/usr/lib conftest.c -lboost_system  -lpthread   >&5
conftest.c:33:6: warning: conflicting types for built-in function 'exit'
 char exit ();
      ^
/usr/lib/libboost_system.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/usr/lib/libboost_system.so: undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/usr/lib/libboost_system.so: undefined reference to `operator delete(void*)'
/usr/lib/libboost_system.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
configure:17257: result: no
configure:17366: error: Could not link against boost_system !

@Toilal
Copy link
Author

Toilal commented Feb 14, 2016

# gcc --version
gcc (Alpine 5.3.0) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@ssiloti
Copy link
Collaborator

ssiloti commented Feb 14, 2016

Ok it looks like the problem is Alpine Linux builds boost with -std=c++11 but because boost libraries don't have pkgconfig files the autotools macro doesn't have any way of knowing that -std=c++11 is required to link with boost. I recommend building libtorrent with bjam instead of autotools.

@Toilal
Copy link
Author

Toilal commented Feb 15, 2016

Thanks ssiloti, I think it's the way to go :). Using bjam, it seems there's a problem with asserts in debug build, but release build (using bjam release from shell) seems to work and I finally have a libtorrent.a as output !

Still have a question though : do you know if python bindings are included in this build ?

Thanks for the help, you can let the issue open a few more, my global objective is to build an as small as possible deluge docker image. I'll let you know if all is OK with this bjam build.

@ssiloti
Copy link
Collaborator

ssiloti commented Feb 15, 2016

To build the python bindings you need to run bjam in the bindings/python directory.

@arvidn arvidn closed this as completed Feb 25, 2016
@Perdjesk
Copy link

Perdjesk commented Apr 17, 2016

I tried the same as @Toilal on alpine linux and hit the same issue with undefined reference to from /usr/lib/libboost_system-mt.so.

Is there a way to specify flags to make configure aware of boost being c++11?
I tried bjam too. But honestly I lost myself in all the flags and targets across different docs. I can't have something clean and working. Even by trying to copy-pasta what is in .travis.yml

EDIT:
You can find my attempts in the following repo:
https://github.com/Perdjesk/deluge-libtorrent/tree/alpine

@arvidn
Copy link
Owner

arvidn commented Apr 17, 2016

did you try adding -std=c++11 to your CXXFLAGS when running ./configure?

@Perdjesk
Copy link

Perdjesk commented Apr 17, 2016

EDIT: @arvidn If you don't mind I would like to keep editing this issue to track the building of libtorrent on alpine-linux. The only available version of libtorrent on alpine repos is sadly 0.16.19

The problem was when configure was checking libboost_system linking with gcc (for whatever reason it was using gcc instead of g++). Some checks are made with g++ and some with gcc. I forced the load of stdc++ when gcc is used with export CFLAGS="-lstdc++" before ./configure.

This seems to do the trick :)
Making some progress...

I have hit another error when configure is checking the boost-python linking.
This one seems purely related to alpine-linux however.

I don't get why libboost_python is complaining because python is linked and those types seem comprised in python2.7. I tried to run this compilation on my Fedora workstation and nothing is wrong with the ordering of the -l -L or -I.
I will look with the alpine community for some help.
The error can be easily reproduced with the conftest.cpp (which is printed in the config.log) and some packages of alpine (boost, boost-dev, g++, python, python-dev)

g++ -o conftest -g -O2 -ftemplate-depth=120 -fvisibility=hidden -fvisibility-inlines-hidden -I/usr/include -I/usr/include/python2.7 -I/usr/
include  -L/usr/lib -L/usr/lib  -fvisibility=hidden -fvisibility-inlines-hidden conftest.cpp -lpython2.7 -lboost_python -lpthread   -L/usr/lib
/tmp/ccLBcFph.o: In function `inittest':
/tmp/libtorrent/conftest.cpp:37: undefined reference to `boost::python::detail::init_module(char const*, void (*)())'
/usr/lib/libboost_python.so: undefined reference to `PyUnicode_FromFormat'
/usr/lib/libboost_python.so: undefined reference to `PyUnicode_AsWideChar'
/usr/lib/libboost_python.so: undefined reference to `PyUnicode_AsUTF8String'
/usr/lib/libboost_python.so: undefined reference to `PyBytes_Size'
/usr/lib/libboost_python.so: undefined reference to `PyModule_Create2'
/usr/lib/libboost_python.so: undefined reference to `_Py_fopen'
/usr/lib/libboost_python.so: undefined reference to `PyUnicode_AsUTF8'
/usr/lib/libboost_python.so: undefined reference to `PyUnicode_FromString'
/usr/lib/libboost_python.so: undefined reference to `PyUnicode_InternFromString'
/usr/lib/libboost_python.so: undefined reference to `PyBytes_AsString'
/usr/lib/libboost_python.so: undefined reference to `PyUnicode_FromStringAndSize'
/usr/lib/libboost_python.so: undefined reference to `PyUnicode_FromEncodedObject'
collect2: error: ld returned 1 exit status

The configure log:

checking whether python bindings should be built... yes
checking for a Python interpreter with version >= 2.4... python
checking for python... /usr/bin/python
checking for python version... 2.7
checking for python platform... linux2
checking for python script directory... ${prefix}/lib/python2.7/site-packages
checking for python extension module directory... ${exec_prefix}/lib/python2.7/site-packages
checking for python2.7... (cached) /usr/bin/python
checking for a version of Python >= '2.1.0'... yes
checking for a version of Python >= '2.4'... yes
checking for the distutils Python package... yes
checking for Python include path... -I/usr/include/python2.7
checking for Python library path... Traceback (most recent call last):
  File "<stdin>", line 8, in <module>
NameError: name 'EOD' is not defined
Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
NameError: name 'EOD' is not defined
Traceback (most recent call last):
  File "<stdin>", line 8, in <module>
NameError: name 'EOD' is not defined
-L/usr/lib -lpython2.7
checking for Python site-packages path... /usr/lib/python2.7/site-packages
checking python extra libraries... -ldl -lm
checking python extra linking flags... -Xlinker -export-dynamic
checking consistency of all components of python development environment... yes
checking whether the Boost::Python library is available... yes
checking whether boost_python is the correct library... no
checking whether boost_python-boost_python is the correct library... no
checking whether boost_python-mt is the correct library... no
checking whether boost_python-mt is the correct library... (cached) no
checking whether boost_python-mt is the correct library... (cached) no
checking whether boost_python is the correct library... (cached) no
checking whether boost_python is the correct library... (cached) no
checking whether boost_python is the correct library... (cached) no
checking whether boost_python3-mt is the correct library... no
checking whether boost_python3-mt is the correct library... (cached) no
checking whether boost_python3-mt is the correct library... (cached) no
checking whether boost_python3 is the correct library... no
checking whether boost_python3 is the correct library... (cached) no
checking whether boost_python3 is the correct library... (cached) no
checking whether boost_python is the correct library... (cached) no
checking whether boost_python3 is the correct library... (cached) no
configure: error: Boost.Python library not found. Try using --with-boost-python=lib.

@Toilal
Copy link
Author

Toilal commented Dec 30, 2016

For googlers coming there, here's a working dockerfile to build libtorrent from scratch on alpine linux stable.

Also alpine edge now packages 1.0.9 version, so building from scratch may not be required if you are able to use alpine edge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants