i2pd
i2pd copied to clipboard
Unable to compile on OpenBSD
Hello,
I was able to compile i2pd on OpenBSD before, but yesterday after pulling the last commits, the compilation failed. I'm using OpenBSD 7.1 with all the patches.
Steps to reproduce:
$ git pull
$ cd build
$ cmake .
$ make
Result:
[Many lines...]
ld: error: undefined symbol: BN_to_montgomery
>>> referenced by Crypto.cpp
>>> Crypto.cpp.o:(i2p::crypto::PrecalculateElggTable(bignum_st* (*) [255], int)) in archive libi2pd.a
ld: error: undefined symbol: BN_is_zero
>>> referenced by Ed25519.cpp
>>> Ed25519.cpp.o:(i2p::crypto::Ed25519::RecoverX(bignum_st const*, bignum_ctx*) const) in archive libi2pd.a
>>> referenced by Ed25519.cpp
>>> Ed25519.cpp.o:(i2p::crypto::Ed25519::Mul(i2p::crypto::EDDSAPoint const&, bignum_st const*, bignum_ctx*) const) in archive libi2pd.a
>>> referenced by Ed25519.cpp
>>> Ed25519.cpp.o:(i2p::crypto::Ed25519::IsOnCurve(i2p::crypto::EDDSAPoint const&, bignum_ctx*) const) in archive libi2pd.a
>>> referenced 2 more times
ld: error: undefined symbol: BN_is_odd
>>> referenced by Ed25519.cpp
>>> Ed25519.cpp.o:(i2p::crypto::Ed25519::RecoverX(bignum_st const*, bignum_ctx*) const) in archive libi2pd.a
ld: error: undefined symbol: BN_is_negative
>>> referenced by Ed25519.cpp
>>> Ed25519.cpp.o:(i2p::crypto::EDDSAPoint::operator-() const) in archive libi2pd.a
>>> referenced by Ed25519.cpp
>>> Ed25519.cpp.o:(i2p::crypto::EDDSAPoint::operator-() const) in archive libi2pd.a
ld: error: undefined symbol: BN_is_word
>>> referenced by Elligator.cpp
>>> Elligator.cpp.o:(i2p::crypto::Elligator2::Legendre(bignum_st const*, bignum_ctx*) const) in archive libi2pd.a
c++: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error 1 in . (CMakeFiles/i2pd.dir/build.make:187 'i2pd': /usr/local/bin/cmake -E cmake_link_script CMakeFiles/i2pd.dir/link.txt --verbos...)
*** Error 2 in . (CMakeFiles/Makefile2:91 'CMakeFiles/i2pd.dir/all': make -s -f CMakeFiles/i2pd.dir/build.make CMakeFiles/i2pd.dir/build)
Since it's a linking problem, I tried to use static linking instead:
$ cmake -D WITH_STATIC=ON .
$ make
Result:
[Many lines...]
ld: error: attempted static link of dynamic object /usr/lib/libssl.so.48.2
ld: error: attempted static link of dynamic object /usr/lib/libcrypto.so.46.2
ld: error: attempted static link of dynamic object /usr/lib/libz.so.5.0
c++: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error 1 in . (CMakeFiles/i2pd.dir/build.make:187 'i2pd': /usr/local/bin/cmake -E cmake_link_script CMakeFiles/i2pd.dir/link.txt --verbos...)
*** Error 2 in . (CMakeFiles/Makefile2:91 'CMakeFiles/i2pd.dir/all': make -s -f CMakeFiles/i2pd.dir/build.make CMakeFiles/i2pd.dir/build)
Which OpenSSL version are you using?
Initially I didn't have to install OpenSSL. OpenBSD ships with LibreSSL and i2pd worked fine with it before. I should try to install OpenSSL to see if it fixes the issue. Which version is known to work?
Unless LibreSSL is supported? If not, are there plans to support other SSL libraries?
Recommended version is 1.1.1.
I installed OpenSSL 1.1.1o (not sure what the "o" stands for), but I get the same error messages as before (with both dynamic and static linking). Is there something I need to do in order to make the linker aware of OpenSSL?
Can you try to build using make in project root?
With make (which is BSD make), I get this:
No closing parenthesis in archive specification
*** Parse error in /home/user/i2pd: Error in archive specification: "(, )" (Makefile:5)
No closing parenthesis in archive specification
*** Parse error: Error in archive specification: "(, )" (Makefile:7)
*** Parse error: Need an operator in 'else' (Makefile:9)
*** Parse error: Need an operator in 'endif' (Makefile:11)
*** Parse error: Missing dependency operator (Makefile:43)
*** Parse error: Need an operator in 'else' (Makefile:45)
*** Parse error: Need an operator in 'endif' (Makefile:48)
No closing parenthesis in archive specification
*** Parse error: Error in archive specification: "(, )" (Makefile:50)
No closing parenthesis in archive specification
*** Parse error: Error in archive specification: "(, )" (Makefile:57)
No closing parenthesis in archive specification
*** Parse error: Error in archive specification: "(, )" (Makefile:60)
No closing parenthesis in archive specification
*** Parse error: Error in archive specification: "(, )" (Makefile:63)
*** Parse error: Missing dependency operator (Makefile:66)
*** Parse error: Need an operator in 'endif' (Makefile:68)
*** Parse error: Missing dependency operator (Makefile:70)
*** Parse error: Need an operator in 'endif' (Makefile:73)
*** Parse error: Filename missing from "-include" (Makefile:112)
*** Parse error: Missing dependency operator (Makefile:118)
*** Parse error: Need an operator in 'endif' (Makefile:120)
*** Parse error: Missing dependency operator (Makefile:123)
*** Parse error: Need an operator in 'endif' (Makefile:125)
*** Parse error: Missing dependency operator (Makefile:128)
*** Parse error: Need an operator in 'endif' (Makefile:130)
*** Parse error: Missing dependency operator (Makefile:133)
*** Parse error: Need an operator in 'endif' (Makefile:135)
With gmake (which is GNU make), I get this:
gmake: g++: No such file or directory
Makefile:67: *** recipe commences before first target. Stop.
Is gcc required? I thought clang was supported.
It is, but nobody tested with it on OpenBSD. You can check how port builds on your system and get some ideas: https://openports.se/net/i2pd
Btw: wrote an email to the maintainer of the OpenBSD port to update it.
Still no reply from package maintainer. @Elcoid how are the results with trying to build an application from a package?
I looked at the makefile in the port, but to be honest I didn't really understand what was in it, and I didn't have much time to work on this since then
Update: The version provided by the port is 2.41.0, but this version compiles fine with LibreSSL, so cannot rely on it unfortunately
I investigated a bit and found that the problem is not related to OpenSSL vs LibreSSL, because LibreSSL provides the functions BN_to_montgomery, BN_is_zero, BN_is_odd, BN_is_negative, and BN_is_word, which are the undefined symbols in the linker's error messages.
The problem seems to be with cmake's config. Commit b8bc1145 compiles correctly on my machine, but commit 4d59df9f doesn't. The only changes in the latter commit were in build/CMakeLists.txt. By reverting the change on one of the lines, I'm able to compile the latest commit. Here's the patch to make the latest commit work on my machine (I replaced OpenSSL::SSL OpenSSL::Crypto with ${OPENSSL_LIBRARIES}):
diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt
index 0c40d5a9..8f8ce84c 100644
--- a/build/CMakeLists.txt
+++ b/build/CMakeLists.txt
@@ -268,7 +268,7 @@ if(WITH_BINARY)
set(DL_LIB ${CMAKE_DL_LIBS})
endif()
- target_link_libraries("${PROJECT_NAME}" libi2pd libi2pdclient libi2pdlang ${DL_LIB} ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto ${MINIUPNPC_LIBRARY} ZLIB::ZLIB Threads::Threads ${DL_LIB} ${CMAKE_REQUIRED_LIBRARIES})
+ target_link_libraries("${PROJECT_NAME}" libi2pd libi2pdclient libi2pdlang ${DL_LIB} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${MINIUPNPC_LIBRARY} ZLIB::ZLIB Threads::Threads ${DL_LIB} ${CMAKE_REQUIRED_LIBRARIES})
install(TARGETS "${PROJECT_NAME}" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime)
set(APPS "\${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME}${CMAKE_EXECUTABLE_SUFFIX}")
Can you check your cmake version and give FindOpenSSL.cmake module version?
cmake is 3.20.3 How can I find the version of a module?
Module can be found in path like /usr/share/cmake-XXX/Modules/FindOpenSSL.cmake, check the file contents for version, but it can lack them. In that case try to check if it contain mentions about imported targets, like OpenSSL::SSL and OpenSSL::Crypto.
Example on Debian 9 with CMake 3.7:
# This module defines the following :prop_tgt:`IMPORTED` targets:
#
# ``OpenSSL::SSL``
# The OpenSSL ``ssl`` library, if found.
# ``OpenSSL::Crypto``
# The OpenSSL ``crypto`` library, if found.
In /usr/local/share/cmake/Modules/FindOpenSSL.cmake, I see the following:
Imported Targets
^^^^^^^^^^^^^^^^
.. versionadded:: 3.4
This module defines the following :prop_tgt:`IMPORTED` targets:
``OpenSSL::SSL``
The OpenSSL ``ssl`` library, if found.
``OpenSSL::Crypto``
The OpenSSL ``crypto`` library, if found.
``OpenSSL::applink``
.. versionadded:: 3.18
But I don't see what seems to be a version number.
Well, It's looks like in v3.20.3 sources (https://github.com/Kitware/CMake/blob/v3.20.3/Modules/FindOpenSSL.cmake)
Anyway, it's best to contact the OpenBSD cmake maintainer about a problem with it, because it should correctly find the OpenSSL libraries and import them as targets.
add: I'm meaning that import: https://cmake.org/cmake/help/latest/module/FindOpenSSL.html#imported-targets
Ok, I'll keep you updated
I received a reply saying the problem could not be reproduced. I tried in a brand new VM and indeed, it compiles just fine! I will try to see what is wrong with my machine and report my findings, in case someone with the same problem finds this in the future.
I uninstalled and reinstalled git, cmake, and boost, then deleted the git repo and recloned it, and now it works. No idea what happened... Anyway, thank you for your help!