使用 NETSSL 支持为 Android 构建 POCO 时出错
Error when building POCO for Android with NETSSL support
我正在尝试为 Android (x86) 构建 POCO,支持 NetSSL_OpenSSL 默认情况下未启用。这是我的配置行:
$ ./configure --config=Android
这是我的 cmake 行:
$ cmake -H. -B./poco-build-x86 -G'Ninja' -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/Users/me/Library/Android/android-ndk-r19c/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=21 -DANDROID_ABI=x86 -DCMAKE_INSTALL_PREFIX:PATH=install-x86 -DOPENSSL_ROOT_DIR=/Users/me/dev/openssl-1.1.1g/install-x86/ -DOPENSSL_CRYPTO_LIBRARY=/Users/me/dev/openssl-1.1.1g/install-x86/lib -DOPENSSL_INCLUDE_DIR=/Users/me/dev/openssl-1.1.1g/install-x86 -DENABLE_CRYPTO=ON -DENABLE_NETSSL=ON
我在 cmake 时遇到这个错误:
-- Checking for C++14 compiler
-- Checking for C++14 compiler - available
-- Could NOT find APR (missing: APR_INCLUDE_DIR APR_LIBRARY)
-- Could NOT find APRUTIL (missing: APRUTIL_INCLUDE_DIR APRUTIL_LIBRARY)
-- Could NOT find Apache2 (missing: APACHE2_INCLUDE_DIR)
-- Could NOT find MYSQL (missing: MYSQL_INCLUDE_DIR MYSQL_LIBRARY)
-- Could NOT find PostgreSQL (missing: PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR)
-- Could NOT find ODBC (missing: ODBC_LIBRARY ODBC_INCLUDE_DIR)
-- Building without tests & samples
-- Using internal sqlite, zlib, pcre, expat, ...
-- SQLite Support Enabled
-- MySQL Support Disabled
-- PostgreSQL Support Disabled
-- ODBC Support Disabled
-- CMake 3.10.2 successfully configured Poco using Ninja generator
-- Poco package version: 1.10.1
-- Building dynamic libraries
-- [cmake] Installation target path: install-x86
-- [cmake] Use toolchain file: /Users/juangarcia/Library/Android/android-ndk-r19c/build/cmake/android.toolchain.cmake
-- [cmake] Bulid for OS type: Android
-- [cmake] Build for OS version: 1
-- [cmake] Build for CPU type: i686
-- [cmake] Build type: Release
-- [cmake] Build with cxx flags: -O2 -DNDEBUG -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++
-- [cmake] Build with c flags: -O2 -DNDEBUG -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security
-- Building: Encodings
-- Building: XML
-- Building: JSON
-- Building: Util
-- Building: Net
-- Building: MongoDB
-- Building: Redis
-- Building: NetSSL_OpenSSL
-- Building: Crypto
-- Building: Data
-- Building: Zip
-- Building: PageCompiler
-- Building: File2Page
-- Configuring done
CMake Error at NetSSL_OpenSSL/CMakeLists.txt:16 (add_library):
Target "NetSSL" 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?
...
我做错了什么?
这个问题的解决方案是使用来自 OpenSSL 的静态库。所以,你需要 link 反对 .a 而不是 .so/.dylib。类似于:
cmake -H. -B./poco-build-x86 -G'Ninja' -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/Users/juangarcia/Library/Android/sdk/cmake/3.10.2.4988404/bin/ninja -DCMAKE_TOOLCHAIN_FILE=/Users/juangarcia/Library/Android/android-ndk-r19c/build/cmake/android.toolchain.cmake -DCMAKE_C_COMPILER=/Users/juangarcia/Library/Android/android-ndk-r19c/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang -DCMAKE_CXX_COMPILER=/Users/juangarcia/Library/Android/android-ndk-r19c/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ -DANDROID_NATIVE_API_LEVEL=24 -DANDROID_ABI=x86 -DOPENSSL_CRYPTO_LIBRARY=/Users/juangarcia/Downloads/openssl_111_android/lib/x86/libcrypto.a -DOPENSSL_SSL_LIBRARY=/Users/juangarcia/Downloads/openssl_111_android/lib/x86/libssl.a -DOPENSSL_USE_STATIC_LIBS=TRUE -DENABLE_NETSSL=TRUE -DOPENSSL_INCLUDE_DIR=/Users/juangarcia/Downloads/openssl_111_android/inc/x86 -DCMAKE_INSTALL_PREFIX=install-x86
你应该注意到,在上面的命令中,我将 CMAKE_INSTALL_PREFIX 设置为自动安装在一个目录中,但这并不是解决问题所必需的。
我正在尝试为 Android (x86) 构建 POCO,支持 NetSSL_OpenSSL 默认情况下未启用。这是我的配置行:
$ ./configure --config=Android
这是我的 cmake 行:
$ cmake -H. -B./poco-build-x86 -G'Ninja' -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/Users/me/Library/Android/android-ndk-r19c/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=21 -DANDROID_ABI=x86 -DCMAKE_INSTALL_PREFIX:PATH=install-x86 -DOPENSSL_ROOT_DIR=/Users/me/dev/openssl-1.1.1g/install-x86/ -DOPENSSL_CRYPTO_LIBRARY=/Users/me/dev/openssl-1.1.1g/install-x86/lib -DOPENSSL_INCLUDE_DIR=/Users/me/dev/openssl-1.1.1g/install-x86 -DENABLE_CRYPTO=ON -DENABLE_NETSSL=ON
我在 cmake 时遇到这个错误:
-- Checking for C++14 compiler
-- Checking for C++14 compiler - available
-- Could NOT find APR (missing: APR_INCLUDE_DIR APR_LIBRARY)
-- Could NOT find APRUTIL (missing: APRUTIL_INCLUDE_DIR APRUTIL_LIBRARY)
-- Could NOT find Apache2 (missing: APACHE2_INCLUDE_DIR)
-- Could NOT find MYSQL (missing: MYSQL_INCLUDE_DIR MYSQL_LIBRARY)
-- Could NOT find PostgreSQL (missing: PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR)
-- Could NOT find ODBC (missing: ODBC_LIBRARY ODBC_INCLUDE_DIR)
-- Building without tests & samples
-- Using internal sqlite, zlib, pcre, expat, ...
-- SQLite Support Enabled
-- MySQL Support Disabled
-- PostgreSQL Support Disabled
-- ODBC Support Disabled
-- CMake 3.10.2 successfully configured Poco using Ninja generator
-- Poco package version: 1.10.1
-- Building dynamic libraries
-- [cmake] Installation target path: install-x86
-- [cmake] Use toolchain file: /Users/juangarcia/Library/Android/android-ndk-r19c/build/cmake/android.toolchain.cmake
-- [cmake] Bulid for OS type: Android
-- [cmake] Build for OS version: 1
-- [cmake] Build for CPU type: i686
-- [cmake] Build type: Release
-- [cmake] Build with cxx flags: -O2 -DNDEBUG -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++
-- [cmake] Build with c flags: -O2 -DNDEBUG -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security
-- Building: Encodings
-- Building: XML
-- Building: JSON
-- Building: Util
-- Building: Net
-- Building: MongoDB
-- Building: Redis
-- Building: NetSSL_OpenSSL
-- Building: Crypto
-- Building: Data
-- Building: Zip
-- Building: PageCompiler
-- Building: File2Page
-- Configuring done
CMake Error at NetSSL_OpenSSL/CMakeLists.txt:16 (add_library):
Target "NetSSL" 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?
...
我做错了什么?
这个问题的解决方案是使用来自 OpenSSL 的静态库。所以,你需要 link 反对 .a 而不是 .so/.dylib。类似于:
cmake -H. -B./poco-build-x86 -G'Ninja' -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/Users/juangarcia/Library/Android/sdk/cmake/3.10.2.4988404/bin/ninja -DCMAKE_TOOLCHAIN_FILE=/Users/juangarcia/Library/Android/android-ndk-r19c/build/cmake/android.toolchain.cmake -DCMAKE_C_COMPILER=/Users/juangarcia/Library/Android/android-ndk-r19c/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang -DCMAKE_CXX_COMPILER=/Users/juangarcia/Library/Android/android-ndk-r19c/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ -DANDROID_NATIVE_API_LEVEL=24 -DANDROID_ABI=x86 -DOPENSSL_CRYPTO_LIBRARY=/Users/juangarcia/Downloads/openssl_111_android/lib/x86/libcrypto.a -DOPENSSL_SSL_LIBRARY=/Users/juangarcia/Downloads/openssl_111_android/lib/x86/libssl.a -DOPENSSL_USE_STATIC_LIBS=TRUE -DENABLE_NETSSL=TRUE -DOPENSSL_INCLUDE_DIR=/Users/juangarcia/Downloads/openssl_111_android/inc/x86 -DCMAKE_INSTALL_PREFIX=install-x86
你应该注意到,在上面的命令中,我将 CMAKE_INSTALL_PREFIX 设置为自动安装在一个目录中,但这并不是解决问题所必需的。