Closed cjserio closed 1 month ago
I also ran into this today. According to the Conan documentation, this should work.
It looks like b2
uses /usr/bin/clang
instead of the cross-toolchain. This becomes evident when trying to build boost without native clang installed (which fails early). When explicitly adding the location of the NDK's clang
to PATH
, it will still produce the error you mentioned (using the correct compiler this time), because clang infers the target architecture from its own filename (defaulting to the host). b2
must call clang via the aarch64-linux-android24-clang
symlinks instead.
In summary, my workaround is to add this section to my Conan profile:
[buildenv]
PATH+=(path)<NDK_PATH>/toolchains/llvm/prebuilt/linux-x86_64/bin/
CC=aarch64-linux-android24-clang
CXX=aarch64-linux-android24-clang++
Ideally, Conan should either infer these automatically, or the documentation should be fixed to provide a fully functional Conan profile.
EDIT: I changed PATH=
to PATH+=(path)
to ensure the NDK binaries path gets appended to PATH rather than replacing it. ((path)
is a magic string recognized by Conan to handle this appropriately.)
You have to consider there is no B2 generator available in Conan (there is an open PR for that). So, any customization should be listed in the Boost recipe directly. When using android-ndk, those extra variables are configured already, including the compiler: https://github.com/conan-io/conan-center-index/blob/master/recipes/android-ndk/all/conanfile.py#L300
So, in case using android-ndk
as tool requirement, Boost will be built nicely for Android. Otherwise, you should configure everything manually in your recipe:
conan create all --version=1.85.0 -pr:b default -pr:h android
boost/1.85.0: Exporting package recipe: /home/uilian/Development/conan/conan-center-index/recipes/boost/all/conanfile.py
boost/1.85.0: exports: File 'conandata.yml' found. Exporting it...
boost/1.85.0: Calling export()
boost/1.85.0: Calling export_sources()
boost/1.85.0: Copied 1 '.py' file: conanfile.py
boost/1.85.0: Copied 2 '.yml' files: conandata.yml, dependencies-1.85.0.yml
boost/1.85.0: Copied 2 '.patch' files: 1.82.0-locale-iconv-library-option.patch, 1.85.0-container-aliasing-violation-fix.patch
boost/1.85.0: Exported to cache folder: /home/uilian/.conan2/p/boosta4755ec112be9/e
boost/1.85.0: Exported: boost/1.85.0#8050df433bd49bb19811ef3e3cf1d0b7 (2024-09-16 07:38:59 UTC)
======== Input profiles ========
Profile host:
[settings]
arch=armv8
build_type=Release
compiler=clang
compiler.cppstd=17
compiler.libcxx=c++_static
compiler.version=17
os=Android
os.api_level=32
[tool_requires]
*: cmake/3.29.7, android-ndk/r26d
[conf]
tools.build:verbosity=verbose
tools.cmake.cmaketoolchain:generator=Ninja
tools.compilation:verbosity=verbose
tools.system.package_manager:mode=install
tools.system.package_manager:sudo=yes
Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=11
os=Linux
[tool_requires]
*: cmake/3.29.7
[conf]
tools.build:verbosity=verbose
tools.cmake.cmaketoolchain:generator=Ninja
tools.compilation:verbosity=verbose
tools.system.package_manager:mode=install
tools.system.package_manager:sudo=yes
======== Computing dependency graph ========
Graph root
cli
Requirements
boost/1.85.0#8050df433bd49bb19811ef3e3cf1d0b7 - Cache
bzip2/1.0.8#457c272f7da34cb9c67456dd217d36c4 - Cache
libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1 - Cache
zlib/1.3.1#f52e03ae3d251dec704634230cd806a2 - Cache
Build requirements
android-ndk/r26d#0a8a020a2e0ce2edbda6ff226a33a23a - Cache
b2/5.2.1#91bc73931a0acb655947a81569ed8b80 - Cache
cmake/3.29.7#cbf5446442af81d8f7e1b6c719e5982b - Cache
Resolved version ranges
b2/[>=5.2 <6]: b2/5.2.1
zlib/[>=1.2.11 <2]: zlib/1.3.1
======== Computing necessary packages ========
boost/1.85.0: Forced build from source
Requirements
boost/1.85.0#8050df433bd49bb19811ef3e3cf1d0b7:59ef2ccd60e2c2ca77db2e2259c6d4944e8a3344 - Build
bzip2/1.0.8#457c272f7da34cb9c67456dd217d36c4:2ff997fe7ebc8a85679750b3fa964fbe19c0d09c#a4dc8ed27fe52539ad497e49aa19ed8d - Cache
libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1:1fb490abea0c07fe60f9417ffad5cf9f74dde6ec#3b2b4152c3dcb2991e1842fee5a8c527 - Cache
zlib/1.3.1#f52e03ae3d251dec704634230cd806a2:1fb490abea0c07fe60f9417ffad5cf9f74dde6ec#c166df81ec333aac702db77c5d0b9829 - Cache
Build requirements
android-ndk/r26d#0a8a020a2e0ce2edbda6ff226a33a23a:63fead0844576fc02943e16909f08fcdddd6f44b#b049c823c3ef83c1c734cd5760bd11aa - Cache
b2/5.2.1#91bc73931a0acb655947a81569ed8b80:63fead0844576fc02943e16909f08fcdddd6f44b#f9c46d924270b1920fa5398114be2576 - Cache
cmake/3.29.7#cbf5446442af81d8f7e1b6c719e5982b:63fead0844576fc02943e16909f08fcdddd6f44b#a394ed2616f3b9d4c653c510e5838734 - Cache
======== Installing packages ========
cmake/3.29.7: Already installed! (1 of 7)
cmake/3.29.7: Appending PATH environment variable: /home/uilian/.conan2/p/cmake97f6298230c3a/p/bin
cmake/3.29.7: Appending PATH environment variable: /home/uilian/.conan2/p/cmake97f6298230c3a/p/bin
android-ndk/r26d: Already installed! (2 of 7)
b2/5.2.1: Already installed! (3 of 7)
bzip2/1.0.8: Already installed! (4 of 7)
libbacktrace/cci.20210118: Already installed! (5 of 7)
zlib/1.3.1: Already installed! (6 of 7)
-------- Installing package boost/1.85.0 (7 of 7) --------
boost/1.85.0: Building from source
boost/1.85.0: Package boost/1.85.0:59ef2ccd60e2c2ca77db2e2259c6d4944e8a3344
boost/1.85.0: Building your package in /home/uilian/.conan2/p/b/boost4c08af286404b/b
boost/1.85.0: Calling generate()
boost/1.85.0: Generators folder: /home/uilian/.conan2/p/b/boost4c08af286404b/b/build-release/conan
boost/1.85.0: Generating aggregated env files
boost/1.85.0: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
boost/1.85.0: Calling build()
boost/1.85.0: WARN: replace_in_file didn't find pattern '$(>) > $(<)' in '/home/uilian/.conan2/p/boosta4755ec112be9/s/src/libs/stacktrace/build/Jamfile.v2' file.
boost/1.85.0: WARN: replace_in_file didn't find pattern '/* thread_local */' in '/home/uilian/.conan2/p/boosta4755ec112be9/s/src/boost/stacktrace/detail/libbacktrace_impls.hpp' file.
boost/1.85.0: WARN: replace_in_file didn't find pattern '/* static __thread */' in '/home/uilian/.conan2/p/boosta4755ec112be9/s/src/boost/stacktrace/detail/libbacktrace_impls.hpp' file.
boost/1.85.0: WARN: replace_in_file didn't find pattern 'local generic-os = [ set.difference $(all-os) : aix darwin vxworks solaris osf hpux ] ;' in '/home/uilian/.conan2/p/boosta4755ec112be9/s/src/tools/build/src/tools/gcc.jam' file.
boost/1.85.0: WARN: replace_in_file didn't find pattern 'local no-threading = android beos haiku sgi darwin vxworks ;' in '/home/uilian/.conan2/p/boosta4755ec112be9/s/src/tools/build/src/tools/gcc.jam' file.
boost/1.85.0: WARN: replace_in_file didn't find pattern ' <conditional>@numa' in '/home/uilian/.conan2/p/boosta4755ec112be9/s/src/libs/fiber/build/Jamfile.v2' file.
boost/1.85.0: WARN: replace_in_file didn't find pattern '! [ $(property-set).get <target-os> ] in windows cygwin darwin aix &&' in '/home/uilian/.conan2/p/boosta4755ec112be9/s/src/boostcpp.jam' file.
boost/1.85.0: WARN: Patching user-config.jam
boost/1.85.0: WARN:
using zlib : 1.3.1 : <include>"/home/uilian/.conan2/p/b/zlib7206d61cf2803/p/include" <search>"/home/uilian/.conan2/p/b/zlib7206d61cf2803/p/lib" <name>z ;
using bzip2 : 1.0.8 : <include>"/home/uilian/.conan2/p/b/bzip2bbc6d9c15ab1e/p/include" <search>"/home/uilian/.conan2/p/b/bzip2bbc6d9c15ab1e/p/lib" <name>bz2 ;
using "clang-linux" : : "/home/uilian/.conan2/p/androc80020a02a776/p/bin/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android32-clang++" :
<archiver>"/home/uilian/.conan2/p/androc80020a02a776/p/bin/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar" <ranlib>"/home/uilian/.conan2/p/androc80020a02a776/p/bin/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib" <compileflags>"--sysroot=/home/uilian/.conan2/p/androc80020a02a776/p/bin/toolchains/llvm/prebuilt/linux-x86_64/sysroot -I/home/uilian/.conan2/p/b/libbad41422dba2b6e/p/include" <linkflags>"--sysroot=/home/uilian/.conan2/p/androc80020a02a776/p/bin/toolchains/llvm/prebuilt/linux-x86_64/sysroot -L/home/uilian/.conan2/p/b/libbad41422dba2b6e/p/lib" ;
boost/1.85.0: Cross building, detecting compiler...
boost/1.85.0: Cross building flags: []
boost/1.85.0: WARN: b2 -q numa=on target-os=android architecture=arm address-model=64 binary-format=elf abi=aapcs --layout=system --user-config=/home/uilian/.conan2/p/boosta4755ec112be9/s/src/tools/build/user-config.jam -sNO_ZLIB=0 -sNO_BZIP2=0 -sNO_LZMA=1 -sNO_ZSTD=1 boost.locale.icu=off --disable-icu boost.locale.iconv=on boost.locale.iconv.lib=libc threading=multi visibility=hidden link=static variant=release --with-atomic --with-charconv --with-chrono --with-container --with-context --with-contract --with-coroutine --with-date_time --with-exception --with-fiber --with-filesystem --with-graph --with-iostreams --with-json --with-locale --with-log --with-math --with-nowide --with-program_options --with-random --with-regex --with-serialization --with-stacktrace --with-system --with-test --with-thread --with-timer --with-type_erasure --with-url --with-wave toolset=clang-linux cxxstd=17 pch=on -sLIBBACKTRACE_PATH=/home/uilian/.conan2/p/b/libbad41422dba2b6e/p define=BOOST_STACKTRACE_LIBCXX_RUNTIME_MAY_CAUSE_MEMORY_LEAK=1 linkflags="" cxxflags="-fPIC -DBOOST_STACKTRACE_ADDR2LINE_LOCATION=/usr/bin/addr2line" install --prefix=/home/uilian/.conan2/p/b/boost4c08af286404b/p -j12 --abbreviate-paths -d2 --debug-configuration --build-dir="/home/uilian/.conan2/p/b/boost4c08af286404b/b/build-release"
boost/1.85.0: RUN: b2 -q numa=on target-os=android architecture=arm address-model=64 binary-format=elf abi=aapcs --layout=system --user-config=/home/uilian/.conan2/p/boosta4755ec112be9/s/src/tools/build/user-config.jam -sNO_ZLIB=0 -sNO_BZIP2=0 -sNO_LZMA=1 -sNO_ZSTD=1 boost.locale.icu=off --disable-icu boost.locale.iconv=on boost.locale.iconv.lib=libc threading=multi visibility=hidden link=static variant=release --with-atomic --with-charconv --with-chrono --with-container --with-context --with-contract --with-coroutine --with-date_time --with-exception --with-fiber --with-filesystem --with-graph --with-iostreams --with-json --with-locale --with-log --with-math --with-nowide --with-program_options --with-random --with-regex --with-serialization --with-stacktrace --with-system --with-test --with-thread --with-timer --with-type_erasure --with-url --with-wave toolset=clang-linux cxxstd=17 pch=on -sLIBBACKTRACE_PATH=/home/uilian/.conan2/p/b/libbad41422dba2b6e/p define=BOOST_STACKTRACE_LIBCXX_RUNTIME_MAY_CAUSE_MEMORY_LEAK=1 linkflags="" cxxflags="-fPIC -DBOOST_STACKTRACE_ADDR2LINE_LOCATION=/usr/bin/addr2line" install --prefix=/home/uilian/.conan2/p/b/boost4c08af286404b/p -j12 --abbreviate-paths -d2 --debug-configuration --build-dir="/home/uilian/.conan2/p/b/boost4c08af286404b/b/build-release"
notice: found boost-build.jam at /home/uilian/.conan2/p/boosta4755ec112be9/s/src/boost-build.jam
notice: loading B2 from /home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/build-system.jam
notice: Searching '/etc' '/home/uilian' '/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/util' '/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/tools' '/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/options' '/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/contrib' '/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/build' '/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2' for site-config configuration file 'site-config.jam'.
notice: Configuration file 'site-config.jam' not found in '/etc' '/home/uilian' '/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/util' '/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/tools' '/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/options' '/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/contrib' '/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/build' '/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2'.
notice: Loading explicitly specified user configuration file:
/home/uilian/.conan2/p/boosta4755ec112be9/s/src/tools/build/user-config.jam
notice: Searching '/home/uilian/.conan2/p/boosta4755ec112be9/s/src/tools/build' for user-config configuration file 'user-config.jam'.
notice: Loading user-config configuration file 'user-config.jam' from '/home/uilian/.conan2/p/boosta4755ec112be9/s/src/tools/build'.
notice: [zlib] Using pre-installed library
notice: [zlib] Condition
notice: [bzip2] Using pre-installed library
notice: [bzip2] Condition
notice: will use '/home/uilian/.conan2/p/androc80020a02a776/p/bin/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android32-clang++' for clang-linux, condition <toolset>clang-linux-17
warning: toolset clang-linux initialization: can not find tool windres
warning: initialized from /home/uilian/.conan2/p/boosta4755ec112be9/s/src/tools/build/user-config.jam:6
notice: using rc compiler :: <toolset>clang-linux-17 :: as
notice: [zlib] zlib is already configured
notice: [bzip2] bzip is already configured
notice: iostreams: not using lzma compression
notice: iostreams: not using zstd compression
notice: [python-cfg] Configuring python...
notice: [python-cfg] Checking interpreter command "python"...
notice: [python-cfg] running command 'python -c "from sys import *; print('version=%d.%d\nplatform=%s\nprefix=%s\nexec_prefix=%s\nexecutable=%s' % (version_info[0],version_info[1],platform,prefix,exec_prefix,executable))" 2>&1'
notice: [python-cfg] ...requested configuration matched!
notice: [python-cfg] Details of this Python configuration:
notice: [python-cfg] interpreter command: "python"
notice: [python-cfg] include path: "/opt/pyenv/versions/3.12.4/include/python3.12"
notice: [python-cfg] library path: "/opt/pyenv/versions/3.12.4/lib/python3.12/config" "/opt/pyenv/versions/3.12.4/lib"
notice: [python-cfg] Checking for NumPy...
notice: [python-cfg] running command 'python -c "import sys; sys.stderr = sys.stdout; import numpy; print(numpy.get_include())"'
notice: [python-cfg] NumPy enabled
/home/uilian/.conan2/p/boosta4755ec112be9/s/src/libs/test/build/../../predef/check/predef.jam:17: in modules.import from module predef
warning: loading predef
warning: circular module loading dependency:
warning: build-system Jamfile</home/uilian/.conan2/p/boosta4755ec112be9/s/src/libs/test/build> predef ==> predef
/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/build/project.jam:1308: in import from module Jamfile</home/uilian/.conan2/p/boosta4755ec112be9/s/src/libs/test/build>
libs/test/build/Jamfile.v2:11: in modules.load from module Jamfile</home/uilian/.conan2/p/boosta4755ec112be9/s/src/libs/test/build>
/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/build/project.jam:544: in load-jamfile from module project
/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/build/project.jam:68: in load from module project
/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/build/project.jam:109: in load-used-projects from module project
/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/build/project.jam:79: in load from module project
/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/build/project.jam:201: in project.find from module project
/home/uilian/.conan2/p/b20717b8c0763fa/p/bin/.b2/build-system.jam:618: in module scope from module build-system
Performing configuration checks
- default address-model : 64-bit [1]
...
clang-linux.compile.c++ /home/uilian/.conan2/p/b/boost4c08af286404b/b/build-release/boost/bin.v2/libs/regex/build/clng-lnx-17/rls/cxstd-17-iso/lnk-sttc/nm-on/trgt-os-andrd/thrd-mlt/vsblt-hdn/regex.o
"/home/uilian/.conan2/p/androc80020a02a776/p/bin/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android32-clang++" -std=c++17 -fvisibility-inlines-hidden -O3 -Wall -fvisibility=hidden -Wno-inline -m64 --sysroot=/home/uilian/.conan2/p/androc80020a02a776/p/bin/toolchains/llvm/prebuilt/linux-x86_64/sysroot -I/home/uilian/.conan2/p/b/libbad41422dba2b6e/p/include -fPIC -DBOOST_STACKTRACE_ADDR2LINE_LOCATION=/usr/bin/addr2line -DBOOST_ALL_NO_LIB=1 -DBOOST_COBALT_USE_STD_PMR=1 -DBOOST_STACKTRACE_LIBCXX_RUNTIME_MAY_CAUSE_MEMORY_LEAK=1 -DBOOST_USE_NUMA -DNDEBUG -I"." -c -o "/home/uilian/.conan2/p/b/boost4c08af286404b/b/build-release/boost/bin.v2/libs/regex/build/clng-lnx-17/rls/cxstd-17-iso/lnk-sttc/nm-on/trgt-os-andrd/thrd-mlt/vsblt-hdn/regex.o" "libs/regex/build/../src/regex.cpp"
I would not see it as a bug, but a misconfiguration from your environment. Please, add tools.build:compiler_executables
to you profile, pointing the expected compiler for Android.
@uilianries Thanks for the reply!
I would not see it as a bug, but a misconfiguration from your environment. Please, add tools.build:compiler_executables to you profile, pointing the expected compiler for Android.
Makes sense, though this would be a documentation bug then. cjserio and I were just copying the Conan documentation. Any chance a functional profile could be listed on that page?
In fact, mentioning CCI's android-ndk package there would also be useful, though personally I would prefer an example that works with a manually installed NDK. So ideally we'd have both: One example profile that works with manual installs, and a simpler one that uses android-ndk as a tool requirement?
Yes thank you so much! I was just going to comment that the docs make no mention of using the NDK as a tool_requires. I was following the docs and pointing the path to my local NDK path which was really clunky because other developers and our CI/CD runners have it installed in different locations. Changing my profile to:
[settings]
arch=armv8
os=Android
os.api_level=24
compiler=clang
compiler.version=14
compiler.libcxx=c++_static
compiler.cppstd=20
[tool_requires]
android-ndk/r25c
has made this much simpler and of course Boost builds properly now.
@cjserio @neobrain Thank you for your feedback! Indeed we discussed about Android examples in the documentation this morning in a meeting. Yes, the documentation can be improved and adding hint about those exceptional cases. Thank you again for giving your thoughts.
@uilianries You said
I would not see it as a bug, but a misconfiguration from your environment. Please, add tools.build:compiler_executables to you profile, pointing the expected compiler for Android.
I didn't notice it until now as I didn't need that to properly compile Boost. All I needed to do was stop hard coding my NDK path and just use the tool_requires with the android-ndk, but now I'm trying to compile freetype/2.13.2 on Android and it's failing because meson is sticking a sys_root path in front of all of my cached conan include paths so nothing's working.
I don't mean to hijack this topic but can you either explain more about this compiler_executables or offer a working and complete example of what an Android profile should look like?
In my attempt to be a good citizen I started a new thread here: https://github.com/conan-io/conan-center-index/issues/25342
Description
I'm experiencing two issues. The first is that when I try to compile with the profile included in this report, I get these assembly errors:
The second issue is that if I disable all of the components (such as context) to get past these error and get boost to compile, when my android app tries to link, I still get these errors:
I've made sure the linker log is showing that I'm linking against the serialization library. The library exists in the proper location...it just doesn't seem to accept the library for some reson.
Package and Environment Details
Conan profile
[settings] arch=armv8 os=Android os.api_level=24 compiler=clang compiler.version=14 compiler.libcxx=c++_static compiler.cppstd=20
[conf] tools.android:ndk_path={{ os.getenv("ANDROID_NDK_ROOT") }}
Steps to reproduce
conan install --requires=boost/1.85.0 --profile=android_profile --build=missing
Logs