我正在尝试在项目中使用 Poco C++ 库,但在为 Android 构建时遇到了一些问题。
我使用 Conan C++ 包管理器作为基础,但我将 Poco 源包含到项目中,并将其子目录包含到项目的顶级 CMakeLists.txt 中,以使过程更加透明。
如果我使用不依赖于 OpenSSL 的 Poco 库构建项目,它构建得很好。如果我添加 Poco 的 NetSSL,那么我会遇到一些与 math.h 相关的问题:
In file included from /home/uname/storage/projects/-some-project-/thirdparty/poco/Crypto/src/Cipher.cpp:15:
In file included from /home/uname/storage/projects/-some-project-/thirdparty/poco/Crypto/include/Poco/Crypto/Cipher.h:22:
In file included from /home/uname/storage/projects/-some-project-/thirdparty/poco/Foundation/include/Poco/RefCountedObject.h:22:
In file included from /home/uname/storage/projects/-some-project-/thirdparty/poco/Foundation/include/Poco/MemoryPool.h:24:
In file included from /home/uname/storage/projects/-some-project-/thirdparty/poco/Foundation/include/Poco/NestedDiagnosticContext.h:24:
In file included from /home/uname/storage/projects/-some-project-/thirdparty/poco/Foundation/include/Poco/OrderedMap.h:28:
In file included from /home/uname/storage/projects/-some-project-/thirdparty/poco/Foundation/include/Poco/ordered_hash.h:31:
/home/uname/.conan/data/android-ndk/r18/theodelrieu/testing/package/2296cbf988942dec6e0ebdfef682b5c678acade8/sources/cxx-stl/llvm-libc++/include/cmath:313:9: error: no member named 'signbit' in the global
namespace; did you mean '__signbit'?
using ::signbit;
~~^
/usr/include/bits/mathcalls-helper-functions.h:25:20: note: '__signbit' declared here
__MATHDECL_1 (int, __signbit,, (_Mdouble_ __value))
据我所知,这是由于路径中早先包含的仅限 C 语言的 math.h 为 libc++ math.h 。有谁知道如何解决这个问题?
实际上,当使用柯南依赖项和构建要求 android-ndk/r18@theodelrieu/testing 或 android_ndk_installer/ r19b@bincrafters/stable 在 Ubuntu 18.04 上。因此,我尝试在不使用 Conan 包的情况下构建 Poco 库和 OpenSSL。
提前感谢您的任何提示或想法!
这是我的安卓版柯南简介:
# --------------------------------------------------------------------------------------------------------------------
# PARAMETERS
#standalone_toolchain=/home/uname/Android/ndk/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64
target_host=armv7a-linux-androideabi
ar_host=arm-linux-androideabi
api_level=21
cc_compiler=clang
cxx_compiler=clang++
# --------------------------------------------------------------------------------------------------------------------
[settings]
os_build=Linux
arch_build=x86_64
compiler=clang
compiler.version=7.0
compiler.libcxx=libc++
os=Android
os.api_level=$api_level
arch=armv7
#Debug/Release
build_type=Debug
# --------------------------------------------------------------------------------------------------------------------
[build_requires]
android-ndk/r18@theodelrieu/testing
#android_ndk_installer/r19b@bincrafters/stable
# --------------------------------------------------------------------------------------------------------------------
[options]
*:shared=False
#Poco:no_asm=True
# --------------------------------------------------------------------------------------------------------------------
[env]
CONAN_CMAKE_FIND_ROOT_PATH=$standalone_toolchain/sysroot
PATH=[$standalone_toolchain/bin]
CHOST=$target_host
# Flags can be also appended after the path to the compiler
CC=$target_host$api_level-$cc_compiler
CXX=$target_host$api_level-$cxx_compiler
CMAKE_C_COMPILER=$CC
CMAKE_CXX_COMPILER=$CXX
AR=$ar_host-ar
AS=$ar_host-as
RANLIB=$target_host-ranlib
LD=$target_host-ld
STRIP=$target_host-strip
CFLAGS= -fPIE -fPIC -I$standalone_toolchain/include/c++/4.9.x
CXXFLAGS= -fPIE -fPIC -I$standalone_toolchain/include/c++/4.9.x
LDFLAGS= -pie
export ANDROID_API=$api_level
OpenSSL:compiler=clang
OpenSSL:options.no_zlib=True
和根 CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(-some-project-)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
## Experimental POCO
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openssl/include) # Path whererever the openssl-dev headers are present
# When compiling the POCO C++ Libraries for a Android target, as well as when including POCO C++ Libraries headers in a project for a Android target, the preprocessor macro POCO_ANDROID must be defined. This is because the Android NDK GCC compiler does not provide a predefined macro that allows for reliable detection of an Android target.
IF(ANDROID)
SET(POCO_ANDROID)
ENDIF()
SET(ENABLE_ENCODINGS OFF)
SET(ENABLE_ENCODINGS_COMPILER OFF)
SET(ENABLE_XML OFF)
SET(ENABLE_JSON ON)
SET(ENABLE_MONGODB OFF)
SET(ENABLE_REDIS OFF)
SET(ENABLE_PDF OFF)
SET(ENABLE_UTIL OFF)
SET(ENABLE_NET ON)
SET(ENABLE_NETSSL ON)
SET(ENABLE_NETSSL_WIN OFF)
SET(ENABLE_CRYPTO OFF)
SET(ENABLE_DATA OFF)
SET(ENABLE_DATA_SQLITE OFF)
SET(ENABLE_DATA_MYSQL OFF)
SET(ENABLE_DATA_ODBC OFF)
SET(ENABLE_SEVENZIP OFF)
SET(ENABLE_ZIP OFF)
SET(ENABLE_APACHECONNECTOR OFF)
SET(ENABLE_CPPPARSER OFF)
SET(ENABLE_POCODOC OFF)
SET(ENABLE_PAGECOMPILER OFF)
SET(ENABLE_PAGECOMPILER_FILE2PAGE OFF)
SET(FORCE_OPENSSL OFF) # Force usage of OpenSSL even under windows
SET(ENABLE_TESTS OFF) # Set to OFF|ON (default is OFF) to control build of POCO tests & samples
SET(POCO_STATIC ON) # Set to OFF|ON (default is OFF) to control build of POCO as STATIC library
SET(POCO_UNBUNDLED OFF) # Set to OFF|ON (default is OFF) to control linking dependencies as external
SET(POCO_BUILD_TYPE "Release")
add_subdirectory(thirdparty/poco)
#SET(OPENSSL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openssl")
## \Experimental POCO
add_subdirectory(src)
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_subdirectory(test)
ENDIF()
PS:我是否使用了正确的方法,还是应该尝试以不同的方式包含和构建 Poco 库和 OpenSSL for Android?主要目标是用于开发和测试的 Android 和 iOS 设备以及本地 macOS 或 Linux。