PurpleI2P / i2pd

🛡 I2P: End-to-End encrypted and anonymous Internet
https://i2pd.website
BSD 3-Clause "New" or "Revised" License
3.31k stars 424 forks source link

Linking fails with BUILD_SHARED_LIBS=ON and LDFLAGS="-Wl,--as-needed" #1353

Closed khumarahn closed 5 years ago

khumarahn commented 5 years ago

Hi!

export LDFLAGS="-Wl,--as-needed"
cmake -DBUILD_SHARED_LIBS=ON .
make

fails with

...
[ 98%] Building CXX object CMakeFiles/i2pd.dir/home/khu/tt/i2pd-2.25.0/daemon/UnixDaemon.cpp.o                                                                           
[100%] Linking CXX executable i2pd
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: libi2pd.so: undefined reference to `boost::gregorian::greg_month::as_short_string() const'
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: libi2pd.so: undefined reference to `boost::gregorian::greg_month::as_long_string() const' 
/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: libi2pd.so: undefined reference to `boost::gregorian::greg_month::get_month_map_ptr[abi:cxx11]()'
collect2: error: ld returned 1 exit status

This came up in bumping gentoo ebuild to the new EAPI, https://github.com/gentoo/gentoo/pull/11998

r4sas commented 5 years ago
ld: libi2pd.so: undefined reference to `boost::gregorian::greg_month::as_short_string() const'
ld: libi2pd.so: undefined reference to `boost::gregorian::greg_month::as_long_string() const' 
ld: libi2pd.so: undefined reference to `boost::gregorian::greg_month::get_month_map_ptr[abi:cxx11]()'

We are not using these functions. Can you try find where it come from?

Also, check if boost_date_time.a is linking and avaliable.

khumarahn commented 5 years ago

Not sure where they come from either.

$ grep 'greg_month' -R .
Binary file ./i2pd-2.25.0/build/CMakeFiles/i2pd.dir/home/khu/tt/i2pd-2.25.0/daemon/I2PControl.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pd.dir/home/khu/tt/i2pd-2.25.0/libi2pd/NTCPSession.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pd.dir/home/khu/tt/i2pd-2.25.0/libi2pd/Profiling.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pd.dir/home/khu/tt/i2pd-2.25.0/libi2pd/Reseed.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pd.dir/home/khu/tt/i2pd-2.25.0/libi2pd/SSU.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pd.dir/home/khu/tt/i2pd-2.25.0/libi2pd/SSUData.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pd.dir/home/khu/tt/i2pd-2.25.0/libi2pd/SSUSession.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pd.dir/home/khu/tt/i2pd-2.25.0/libi2pd/Streaming.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pd.dir/home/khu/tt/i2pd-2.25.0/libi2pd/Destination.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pd.dir/home/khu/tt/i2pd-2.25.0/libi2pd/Transports.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pd.dir/home/khu/tt/i2pd-2.25.0/libi2pd/Datagram.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pd.dir/home/khu/tt/i2pd-2.25.0/libi2pd/Timestamp.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pd.dir/home/khu/tt/i2pd-2.25.0/libi2pd/NTCP2.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pdclient.dir/home/khu/tt/i2pd-2.25.0/libi2pd_client/ClientContext.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pdclient.dir/home/khu/tt/i2pd-2.25.0/libi2pd_client/AddressBook.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pdclient.dir/home/khu/tt/i2pd-2.25.0/libi2pd_client/MatchedDestination.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pdclient.dir/home/khu/tt/i2pd-2.25.0/libi2pd_client/I2PTunnel.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pdclient.dir/home/khu/tt/i2pd-2.25.0/libi2pd_client/I2PService.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pdclient.dir/home/khu/tt/i2pd-2.25.0/libi2pd_client/SAM.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pdclient.dir/home/khu/tt/i2pd-2.25.0/libi2pd_client/SOCKS.cpp.o matches
Binary file ./i2pd-2.25.0/build/CMakeFiles/libi2pdclient.dir/home/khu/tt/i2pd-2.25.0/libi2pd_client/HTTPProxy.cpp.o matches
Binary file ./i2pd-2.25.0/build/libi2pd.so matches
Binary file ./i2pd-2.25.0/build/libi2pdclient.so matches

The build completes fine if I leave out either --as-needed or BUILD_SHARED_LIBS=ON.

khumarahn commented 5 years ago

I wonder if anyone else can reproduce this on their machines. Just run the three lines in the first post.

khumarahn commented 5 years ago

Just tried in Ubuntu 18.04 chroot:

[ 98%] Building CXX object CMakeFiles/i2pd.dir/root/tt/i2pd/daemon/UnixDaemon.cpp.o
[100%] Linking CXX executable i2pd
libi2pd.so: undefined reference to `boost::gregorian::greg_month::as_short_string() const'
libi2pd.so: undefined reference to `crc32'
libi2pd.so: undefined reference to `inflateInit2_'
libi2pd.so: undefined reference to `deflateParams'
libi2pd.so: undefined reference to `adler32'
libi2pd.so: undefined reference to `inflate'
libi2pd.so: undefined reference to `deflateReset'
libi2pd.so: undefined reference to `deflateInit2_'
libi2pd.so: undefined reference to `boost::gregorian::greg_month::as_long_string() const'
libi2pd.so: undefined reference to `inflateReset'
libi2pd.so: undefined reference to `deflate'
libi2pd.so: undefined reference to `boost::gregorian::greg_month::get_month_map_ptr[abi:cxx11]()'
libi2pd.so: undefined reference to `deflateEnd'
libi2pd.so: undefined reference to `inflateEnd'
collect2: error: ld returned 1 exit status
CMakeFiles/i2pd.dir/build.make:233: recipe for target 'i2pd' failed
make[2]: *** [i2pd] Error 1
CMakeFiles/Makefile2:68: recipe for target 'CMakeFiles/i2pd.dir/all' failed
make[1]: *** [CMakeFiles/i2pd.dir/all] Error 2
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2
orignal commented 5 years ago

Так тут zlib нужен

r4sas commented 5 years ago

zlib это одно, а вот почему корректно не линкуется date_time?

khumarahn commented 5 years ago

zlib1g-dev и zlib1g у меня поставлены

r4sas commented 5 years ago

Deb8:

[ 98%] Building CXX object CMakeFiles/i2pd.dir/root/dev/PurpleI2P/i2pd/daemon/UPnP.cpp.o
[100%] Building CXX object CMakeFiles/i2pd.dir/root/dev/PurpleI2P/i2pd/daemon/UnixDaemon.cpp.o
Linking CXX executable i2pd
[100%] Built target i2pd
khumarahn commented 5 years ago

а какая версия компилятора в дебиане 8?

r4sas commented 5 years ago
# gcc -v
...
gcc version 4.9.2 (Debian 4.9.2-10+deb8u2)
khumarahn commented 5 years ago

о, жесть. Там наверное ещё нет as-needed?

r4sas commented 5 years ago

возможно

khumarahn commented 5 years ago

Я поставил дебиан stable c gcc-6.3. Там ошибка воспроизводится как в убунте:

[100%] Linking CXX executable i2pd
libi2pd.so: undefined reference to `boost::gregorian::greg_month::as_short_string() const'
libi2pd.so: undefined reference to `crc32'
libi2pd.so: undefined reference to `inflateInit2_'
libi2pd.so: undefined reference to `deflateParams'
libi2pd.so: undefined reference to `adler32'
libi2pd.so: undefined reference to `inflate'
libi2pd.so: undefined reference to `deflateReset'
libi2pd.so: undefined reference to `deflateInit2_'
libi2pd.so: undefined reference to `boost::gregorian::greg_month::as_long_string() const'
libi2pd.so: undefined reference to `inflateReset'
libi2pd.so: undefined reference to `deflate'
libi2pd.so: undefined reference to `boost::gregorian::greg_month::get_month_map_ptr[abi:cxx11]()'
libi2pd.so: undefined reference to `deflateEnd'
libi2pd.so: undefined reference to `inflateEnd'
collect2: error: ld returned 1 exit status
khumarahn commented 5 years ago

A solution might be to link libi2pd against boost and zlib:

diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt
index e50bbc86..949f6a46 100644
--- a/build/CMakeLists.txt
+++ b/build/CMakeLists.txt
@@ -470,6 +470,7 @@ if (WITH_BINARY)
   if (WITH_STATIC)
     set(DL_LIB ${CMAKE_DL_LIBS})
   endif()
+  target_link_libraries(libi2pd ${Boost_LIBRARIES} ${ZLIB_LIBRARY})
   target_link_libraries( "${PROJECT_NAME}" libi2pd libi2pdclient ${DL_LIB} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MINGW_EXTRA} ${DL_LIB} ${CMAKE_REQUIRED_LIBRARIES})

   install(TARGETS "${PROJECT_NAME}" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime)
khumarahn commented 5 years ago

по крайней мере, так оно собирается и под гентой, и под дебианом

khumarahn commented 5 years ago

Так что насчёт включения target_link_libraries(libi2pd ${Boost_LIBRARIES} ${ZLIB_LIBRARY}) в CMakeLists.txt? Я мало понимаю в линковке, но вроде это то что надо, чтобы решить проблему с --as-needed.

orignal commented 5 years ago

Так поправь. Я в cmake-е это мало что понимаю

khumarahn commented 5 years ago

Отлично, спасибо!