我在尝试在 ubuntu 系统上为 android 平台构建 openvpn3 时遇到 cmake 错误。 CMake 生成步骤失败,提示:
CMake Error at test/ovpncli/CMakeLists.txt:10 (add_library):
Target "xkey" links to target "OpenSSL::SSL" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?
CMake Error at test/ovpncli/CMakeLists.txt:20 (add_executable):
Target "ovpncli" links to target "OpenSSL::SSL" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at test/ovpncli/CMakeLists.txt:20 (add_executable):
Target "ovpncli" links to target "OpenSSL::SSL" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
如果坚持并尝试对失败的构建文件执行 make 命令,这就是我得到的错误
[ 20%] Building C object test/ovpncli/CMakeFiles/xkey.dir/__/__/openvpn/openssl/xkey/xkey_helper.c.o
In file included from /home/e03014/e03014/openvpn3/openvpn/openssl/xkey/xkey_helper.c:15:
/home/e03014/e03014/openvpn3/openvpn/openssl/xkey/xkey_common.h:24:10: fatal error: 'openssl/opensslv.h' file not found
24 | #include <openssl/opensslv.h>
| ^~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [test/ovpncli/CMakeFiles/xkey.dir/build.make:76: test/ovpncli/CMakeFiles/xkey.dir/__/__/openvpn/openssl/xkey/xkey_helper.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:190: test/ovpncli/CMakeFiles/xkey.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
我在根级别执行的cmake命令如下:
cmake -DOPENSSL_ROOT_DIR=../openssl -DOPENSSL_LIBRARY=../openssl/build/lib/libssl.so -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-21 -DBUILD_TESTING=OFF -DOPENSSL_CRYPTO_LIBRARY=../openssl/build/lib/libcrypto.so -DOPENSSL_INCLUDE_DIR=/home/userName/userName/openssl/build/include -DASIO_INCLUDE_DIR=/home/userName/userName/asio/asio/include -DLZ4_INCLUDE_DIR=/home/userName/userName/lz4/lib -DLZ4_LIBRARY=/home/userName/userName/lz4/lib/liblz4.so -DOPENVPN3_BUILD_OVPNCLI=OFF -Bbuild
上述路径均经过充分验证;可能产生上述错误的唯一原因是为标志 -DOPENSSL_INCLUDE_DIR 提供了错误的路径,但我已经一次又一次地验证提供的补丁是正确的,并且它确实包含所需的 .h 文件。
如果我找到了相同的解决方案,因此能够正确执行 cmake 命令;问题在于 cmake 命令,显然 OPENSSL_ROOT_DIR 标志应该指向构建目录。这是我使用的cmake命令:
cmake -DANDROID_ABI=arm64-v8a -DOPENSSL_ROOT_DIR=../openssl/build -DOPENSSL_CRYPTO_LIBRARY=../openssl/build/lib/libcrypto.so -DOPENSSL_SSL_LIBRARY=../openssl/build/lib/libssl.so -DOPENSSL_INCLUDE_DIR=../openssl/build/include -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake -DBUILD_SHARED_LIBS=ON -DANDROID_PLATFORM=android-24 -DBUILD_TESTING=OFF -DASIO_INCLUDE_DIR=/home/e03014/e03014/asio/asio/include -DLZ4_INCLUDE_DIR=/home/e03014/e03014/lz4/lib -DLZ4_LIBRARY=/home/e03014/e03014/lz4/lib/liblz4.so -DBUILD_SWIG_LIB=ON -Bbuild