i2pd icon indicating copy to clipboard operation
i2pd copied to clipboard

Unable to compile on OpenBSD

Open Elcoid opened this issue 3 years ago • 11 comments

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)

Elcoid avatar Jul 15 '22 16:07 Elcoid

Which OpenSSL version are you using?

r4sas avatar Jul 15 '22 20:07 r4sas

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?

Elcoid avatar Jul 16 '22 17:07 Elcoid

Unless LibreSSL is supported? If not, are there plans to support other SSL libraries?

Elcoid avatar Jul 16 '22 18:07 Elcoid

Recommended version is 1.1.1.

r4sas avatar Jul 16 '22 19:07 r4sas

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?

Elcoid avatar Jul 17 '22 02:07 Elcoid

Can you try to build using make in project root?

r4sas avatar Jul 17 '22 10:07 r4sas

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.

Elcoid avatar Jul 18 '22 15:07 Elcoid

Is gcc required? I thought clang was supported.

Elcoid avatar Jul 20 '22 15:07 Elcoid

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.

r4sas avatar Jul 21 '22 20:07 r4sas

Still no reply from package maintainer. @Elcoid how are the results with trying to build an application from a package?

r4sas avatar Aug 05 '22 08:08 r4sas

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

Elcoid avatar Aug 05 '22 11:08 Elcoid

Update: The version provided by the port is 2.41.0, but this version compiles fine with LibreSSL, so cannot rely on it unfortunately

Elcoid avatar Sep 13 '22 13:09 Elcoid

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}")

Elcoid avatar Sep 13 '22 19:09 Elcoid

Can you check your cmake version and give FindOpenSSL.cmake module version?

r4sas avatar Sep 13 '22 20:09 r4sas

cmake is 3.20.3 How can I find the version of a module?

Elcoid avatar Sep 13 '22 20:09 Elcoid

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.

r4sas avatar Sep 13 '22 20:09 r4sas

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.

Elcoid avatar Sep 13 '22 20:09 Elcoid

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

r4sas avatar Sep 13 '22 21:09 r4sas

Ok, I'll keep you updated

Elcoid avatar Sep 13 '22 21:09 Elcoid

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.

Elcoid avatar Sep 14 '22 15:09 Elcoid

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!

Elcoid avatar Sep 14 '22 17:09 Elcoid