今天在Windows平台如下正常执行conan NDK交叉编译Boost库时报了个错
$ conan install boost/1.69.0@ -pr:h android_21_armv7a_clang -pr:b default --build missing
错误日志如下,看样子是在编译依赖库bzip2时出错了,还没到编译boost的阶段
bzip2/1.0.8: Configuring sources in C:\Users\gyd\.conan\data\bzip2\1.0.8\_\_\source
Downloading bzip2-1.0.8.tar.gz completed [791.04k]
bzip2/1.0.8: Copying sources to build folder
bzip2/1.0.8: Building your package in C:\Users\gyd\.conan\data\bzip2\1.0.8\_\_\build\deac87feb545b6b90ea1825dffccbb58b211ca1b
bzip2/1.0.8: Generator cmake created conanbuildinfo.cmake
bzip2/1.0.8: Aggregating env generators
bzip2/1.0.8: Calling build()
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
bzip2/1.0.8:
bzip2/1.0.8: ERROR: Package 'deac87feb545b6b90ea1825dffccbb58b211ca1b' build failed
bzip2/1.0.8: WARN: Build folder C:\Users\gyd\.conan\data\bzip2\1.0.8\_\_\build\deac87feb545b6b90ea1825dffccbb58b211ca1b
ERROR: bzip2/1.0.8: Error in build() method, line 67
cmake = self._configure_cmake()
while calling '_configure_cmake', line 61
self._cmake.configure()
ConanException: Error 1 while executing cd C:\Users\gyd\.conan\data\bzip2\1.0.8\_\_\build\deac87feb545b6b90ea1825dffccbb58b211ca1b && cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_TOOLCHAIN_FILE="C:\android-ndk-r19c\build\cmake\android.toolchain.cmake" -DCONAN_IN_LOCAL_CACHE="ON" -DCONAN_COMPILER="clang" -DCONAN_COMPILER_VERSION="8" -DBUILD_SHARED_LIBS="OFF" -DCMAKE_INSTALL_PREFIX="C:\Users\gyd\.conan\data\bzip2\1.0.8\_\_\package\deac87feb545b6b90ea1825dffccbb58b211ca1b" -DCMAKE_INSTALL_BINDIR="bin" -DCMAKE_INSTALL_SBINDIR="bin" -DCMAKE_INSTALL_LIBEXECDIR="bin" -DCMAKE_INSTALL_LIBDIR="lib" -DCMAKE_INSTALL_INCLUDEDIR="include" -DCMAKE_INSTALL_OLDINCLUDEDIR="include" -DCMAKE_INSTALL_DATAROOTDIR="share" -DCONAN_CMAKE_POSITION_INDEPENDENT_CODE="ON" -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" -DCONAN_EXPORTED="1" -DBZ2_VERSION_STRING="1.0.8" -DBZ2_VERSION_MAJOR="1" -DBZ2_BUILD_EXE="True" -Wno-dev C:\Users\gyd\.conan\data\bzip2\1.0.8\_\_\build\deac87feb545b6b90ea1825dffccbb58b211ca1b
似乎是需要MinGW编译器啊,刚才开始我的解决方法,就是装个MinGW编译器,将C:\mingw64\bin
设置到环境变量PATH
,然后就解决了这个问题。
但我还是觉得不太对,Android NDK交叉编译为什么需要MinGW(mingw64 )编译器呢?这不合理啊。
在Conan issue找到了同款问题:
《Some CMake Settings Passed On With Build Missing on Cross Build #3884》
真正的原因是没有指定CMake的GENERATOR,导致某些库的编译脚本误定义为MinGW Makefiles
,下面是解决方法:
就是需要设置环境变量CONAN_CMAKE_GENERATOR
为Unix Makefiles
可以如下在命令行临时设置环境变量:
set CONAN_CMAKE_GENERATOR=Unix Makefiles
也可以如下将它添加到profile,注意这里Unix Makefiles
需要加引号("
)
android_armv7a_clang
include(default)
android_ndk=D:\j\android-ndk-r19c
target_host=armv7a-linux-androideabi
api_level=16
[settings]
arch=armv7
build_type=Release
compiler=clang
compiler.libcxx=c++_static
#compiler.libcxx=c++_shared
compiler.version=8
os=Android
os.api_level=$api_level
#[tool_requires]
[options]
addr2line_location=$android_ndk\toolchains\llvm\prebuilt\windows-x86_64\bin\x86_64-linux-android-addr2line.exe
[env]
PATH=[$android_ndk\toolchains\llvm\prebuilt\windows-x86_64\bin]
CHOST=$target_host
AR=arm-linux-androideabi-ar
AS=arm-linux-androideabi-as
RANLIB=arm-linux-androideabi-ranlib
CC=$target_host$api_level-clang.cmd
CXX=$target_host$api_level-clang++.cmd
LD=arm-linux-androideabi-ld
STRIP=arm-linux-androideabi-strip
CONAN_CMAKE_TOOLCHAIN_FILE=$android_ndk\build\cmake\android.toolchain.cmake
CONAN_CMAKE_GENERATOR="Unix Makefiles"
[conf]
tools.android:ndk_path=$android_ndk
CONAN_CMAKE_GENERATOR与上面profile中的CONAN_CMAKE_TOOLCHAIN_FILE一样都是conan自定义的环境变量,
关于conan 环境变量的说明参见Conan官方文档《Environment variables》