conan入门(二十七):因profile [env]字段废弃导致的boost/1.81.0 在aarch64-linux-gnu下交叉编译失败

今天在尝试用conan 1.60.0使用aarch64-linux-gnu编译器交叉编译boost/1.81.0时报错了:

conan install boost/1.81.0@ -pr:h aarch64-linux-gnu.jinja -pr:b default --build boost

输出如下:

Configuration (profile_host):
[settings]
arch=armv8
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=7
os=Linux
os_build=Linux
[options]
[build_requires]
[env]
AR=aarch64-linux-gnu-ar
AS=aarch64-linux-gnu-as
CC=aarch64-linux-gnu-gcc
CHOST=aarch64-linux-gnu
CONAN_CMAKE_GENERATOR=Unix Makefiles
CONAN_CMAKE_TOOLCHAIN_FILE=/home/gyd/.conan/profiles/../cmake/aarch64-linux-gnu.toolchain.cmake
CROSS_COMPILER_PREFIX=/opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu
CXX=aarch64-linux-gnu-g++
LD=aarch64-linux-gnu-ld
RANLIB=aarch64-linux-gnu-ranlib
STRIP=aarch64-linux-gnu-strip
Configuration (profile_build):
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=11
os=Linux
os_build=Linux
[options]
[build_requires]
[env]

boost/1.81.0: Forced build from source
Installing package: boost/1.81.0
Requirements
    boost/1.81.0 from 'pub' - Cache
    bzip2/1.0.8 from 'pub' - Cache
    libbacktrace/cci.20210118 from 'pub' - Cache
    zlib/1.2.13 from 'pub' - Cache
Packages
    boost/1.81.0:3aac81ffa04cca0028f0506d5a46ab398161b6d4 - Build
    bzip2/1.0.8:75c0a8a066a2422a4e85cba63decf52760f1010c - Cache
    libbacktrace/cci.20210118:8fd38d381db52e2495321ce060b9f457656f6c8f - Cache
    zlib/1.2.13:8fd38d381db52e2495321ce060b9f457656f6c8f - Cache
Build requirements
    b2/4.9.6 from 'conancenter' - Cache
Build requirements packages
    b2/4.9.6:4db1be536558d833e52e862fd84d64d75c2b3656 - Cache

Cross-build from 'Linux:x86_64' to 'Linux:armv8'
Installing (downloading, building) binaries...
b2/4.9.6: Already installed!
bzip2/1.0.8: Already installed!
libbacktrace/cci.20210118: Already installed!
zlib/1.2.13: Already installed!
boost/1.81.0: Applying build-requirement: b2/4.9.6
boost/1.81.0: WARN: Build folder is dirty, removing it: /home/gyd/.conan/data/boost/1.81.0/_/_/build/3aac81ffa04cca0028f0506d5a46ab398161b6d4
boost/1.81.0: Building your package in /home/gyd/.conan/data/boost/1.81.0/_/_/build/3aac81ffa04cca0028f0506d5a46ab398161b6d4
boost/1.81.0: Generator txt created conanbuildinfo.txt
boost/1.81.0: Calling generate()
boost/1.81.0: Aggregating env generators
boost/1.81.0: Calling build()
boost/1.81.0: WARN: replace_in_file didn't find pattern '$(>) > $(<)' in '/home/gyd/.conan/data/boost/1.81.0/_/_/source/src/libs/stacktrace/build/Jamfile.v2' file.
boost/1.81.0: WARN: replace_in_file didn't find pattern '/* thread_local */' in '/home/gyd/.conan/data/boost/1.81.0/_/_/source/src/boost/stacktrace/detail/libbacktrace_impls.hpp' file.
boost/1.81.0: WARN: replace_in_file didn't find pattern '/* static __thread */' in '/home/gyd/.conan/data/boost/1.81.0/_/_/source/src/boost/stacktrace/detail/libbacktrace_impls.hpp' file.
boost/1.81.0: WARN: replace_in_file didn't find pattern 'local generic-os = [ set.difference $(all-os) : aix darwin vxworks solaris osf hpux ] ;' in '/home/gyd/.conan/data/boost/1.81.0/_/_/source/src/tools/build/src/tools/gcc.jam' file.
boost/1.81.0: WARN: replace_in_file didn't find pattern 'local no-threading = android beos haiku sgi darwin vxworks ;' in '/home/gyd/.conan/data/boost/1.81.0/_/_/source/src/tools/build/src/tools/gcc.jam' file.
boost/1.81.0: WARN: replace_in_file didn't find pattern '    <conditional>@numa' in '/home/gyd/.conan/data/boost/1.81.0/_/_/source/src/libs/fiber/build/Jamfile.v2' file.
boost/1.81.0: WARN: Patching user-config.jam
boost/1.81.0: WARN: 
using zlib : 1.2.13 : <include>"/home/gyd/.conan/data/zlib/1.2.13/_/_/package/8fd38d381db52e2495321ce060b9f457656f6c8f/include" <search>"/home/gyd/.conan/data/zlib/1.2.13/_/_/package/8fd38d381db52e2495321ce060b9f457656f6c8f/lib" <name>z ;
using bzip2 : 1.0.8 : <include>"/home/gyd/.conan/data/bzip2/1.0.8/_/_/package/75c0a8a066a2422a4e85cba63decf52760f1010c/include" <search>"/home/gyd/.conan/data/bzip2/1.0.8/_/_/package/75c0a8a066a2422a4e85cba63decf52760f1010c/lib" <name>bz2 ;
using "gcc" :  :  "/usr/bin/g++" : 
<compileflags>"-I/home/gyd/.conan/data/libbacktrace/cci.20210118/_/_/package/8fd38d381db52e2495321ce060b9f457656f6c8f/include" <linkflags>"-L/home/gyd/.conan/data/libbacktrace/cci.20210118/_/_/package/8fd38d381db52e2495321ce060b9f457656f6c8f/lib"  ;
boost/1.81.0: Cross building, detecting compiler...
boost/1.81.0: Cross building flags: []
boost/1.81.0: WARN: b2 -q numa=on target-os=linux architecture=arm address-model=64 binary-format=elf abi=aapcs --layout=system --user-config=/home/gyd/.conan/data/boost/1.81.0/_/_/source/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-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=gcc define=_GLIBCXX_USE_CXX11_ABI=1 pch=on -sLIBBACKTRACE_PATH=/home/gyd/.conan/data/libbacktrace/cci.20210118/_/_/package/8fd38d381db52e2495321ce060b9f457656f6c8f linkflags="" cxxflags="-fPIC -DBOOST_STACKTRACE_ADDR2LINE_LOCATION=/usr/bin/addr2line" install --prefix=/home/gyd/.conan/data/boost/1.81.0/_/_/package/3aac81ffa04cca0028f0506d5a46ab398161b6d4 -j4 --abbreviate-paths -d0 --debug-configuration --build-dir="/home/gyd/.conan/data/boost/1.81.0/_/_/build/3aac81ffa04cca0028f0506d5a46ab398161b6d4/build-release"
notice: found boost-build.jam at /home/gyd/.conan/data/boost/1.81.0/_/_/source/src/boost-build.jam
notice: loading B2 from /home/gyd/.conan/data/b2/4.9.6/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/kernel/bootstrap.jam
notice: Searching '/etc' '/home/gyd' '/home/gyd/.conan/data/b2/4.9.6/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/kernel' '/home/gyd/.conan/data/b2/4.9.6/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/util' '/home/gyd/.conan/data/b2/4.9.6/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/build' '/home/gyd/.conan/data/b2/4.9.6/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/tools' '/home/gyd/.conan/data/b2/4.9.6/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/contrib' '/home/gyd/.conan/data/b2/4.9.6/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/.' for site-config configuration file 'site-config.jam'.
notice: Configuration file 'site-config.jam' not found in '/etc' '/home/gyd' '/home/gyd/.conan/data/b2/4.9.6/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/kernel' '/home/gyd/.conan/data/b2/4.9.6/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/util' '/home/gyd/.conan/data/b2/4.9.6/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/build' '/home/gyd/.conan/data/b2/4.9.6/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/tools' '/home/gyd/.conan/data/b2/4.9.6/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/contrib' '/home/gyd/.conan/data/b2/4.9.6/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/.'.
notice: Loading explicitly specified user configuration file:
    /home/gyd/.conan/data/boost/1.81.0/_/_/source/src/tools/build/user-config.jam
notice: Searching '/home/gyd/.conan/data/boost/1.81.0/_/_/source/src/tools/build' for user-config configuration file 'user-config.jam'.
notice: Loading user-config configuration file 'user-config.jam' from '/home/gyd/.conan/data/boost/1.81.0/_/_/source/src/tools/build'.
notice: [zlib] Using pre-installed library
notice: [zlib] Condition
notice: [bzip2] Using pre-installed library
notice: [bzip2] Condition
notice: will use '/usr/bin/g++' for gcc, condition <toolset>gcc-11
notice: using gcc libraries :: <toolset>gcc-11 :: /usr/bin /usr/lib /usr/lib32 /usr/lib64
notice: using gcc archiver :: <toolset>gcc-11 :: /usr/bin/ar
warning: toolset gcc initialization: can not find tool windres
warning: initialized from /home/gyd/.conan/data/boost/1.81.0/_/_/source/src/tools/build/user-config.jam:5
notice: using rc compiler :: <toolset>gcc-11 :: /usr/bin/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: "/usr/include/python3.10"
notice: [python-cfg]   library path: "/usr/lib/python3.10/config" "/usr/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 disabled. Reason:
notice: [python-cfg]   python -c "import sys; sys.stderr = sys.stdout; import numpy; print(numpy.get_include())" aborted with 
notice: [python-cfg]   Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
Performing configuration checks

    - default address-model    : 64-bit [1]
    - default architecture     : x86 [1]
    - has std::atomic_ref      : no [2]
    - has statx                : yes [2]
    - has init_priority attribute : yes [2]
    - has stat::st_blksize     : yes [2]
    - has stat::st_mtim        : yes [2]
    - has stat::st_mtimensec   : no [2]
    - has stat::st_mtimespec   : no [2]
    - has stat::st_birthtim    : no [2]
    - has stat::st_birthtimensec : no [2]
    - has stat::st_birthtimespec : no [2]
    - has fdopendir(O_NOFOLLOW) : yes [2]
    - has POSIX *at APIs       : yes [2]
    - cxx11_auto_declarations  : yes [2]
    - cxx11_constexpr          : yes [2]
    - cxx11_defaulted_functions : yes [2]
    - cxx11_final              : yes [2]
    - cxx11_hdr_mutex          : yes [2]
    - cxx11_hdr_tuple          : yes [2]
    - cxx11_lambdas            : yes [2]
    - cxx11_noexcept           : yes [2]
    - cxx11_nullptr            : yes [2]
    - cxx11_rvalue_references  : yes [2]
    - cxx11_template_aliases   : yes [2]
    - cxx11_thread_local       : yes [2]
    - cxx11_variadic_templates : yes [2]
    - has_icu builds           : no [2]
    - zlib                     : yes [3]
    - bzip2                    : no [3]
    - cxx11_decltype           : yes [2]
    - cxx11_basic_alignas      : yes [2]
    - iconv (libc)             : yes [2]
    - cxx11_defaulted_moves    : yes [2]
    - cxx11_hdr_functional     : yes [2]
    - cxx11_hdr_type_traits    : yes [2]
    - cxx11_override           : yes [2]
    - cxx11_range_based_for    : yes [2]
    - cxx11_scoped_enums       : yes [2]
    - cxx11_smart_ptr          : yes [2]
    - cxx11_static_assert      : yes [2]
    - native atomic int32 supported : yes [2]
    - native syslog supported  : yes [2]
    - pthread supports robust mutexes : yes [2]
    - lockfree boost::atomic_flag : yes [2]
    - gcc visibility           : yes [2]
    - sfinae_expr              : yes [2]
    - cxx11_unified_initialization_syntax : yes [2]
    - cxx11_hdr_initializer_list : yes [2]
    - cxx11_hdr_chrono         : yes [2]
    - cxx11_numeric_limits     : yes [2]
    - cxx11_hdr_array          : yes [2]
    - cxx11_hdr_atomic         : yes [2]
    - cxx11_allocator          : yes [2]
    - cxx11_explicit_conversion_operators : yes [2]
    - long double support      : yes [2]
    - std::fstream is moveable and swappable : yes [2]
    - Has Large File Support   : yes [2]
    - Has attribute init_priority : yes [2]
    - libbacktrace builds      : yes [2]
    - addr2line builds         : yes [2]
    - WinDbg builds            : no [2]
    - WinDbg builds            : no [4]
    - WinDbgCached builds      : no [2]
    - WinDbgCached builds      : no [4]
    - BOOST_COMP_GNUC >= 4.3.0 : yes [2]
    - cxx11_hdr_thread         : yes [2]
    - cxx11_hdr_regex          : yes [2]

[1] gcc-11
[2] gcc-11/rls/abi-apcs/archt-arm/bst.l-lbc/bst.l-on/bst.l-off/lnk-sttc/nm-on/pythn-3.10/thrdp-pthrd/thrd-mlt/vsblt-hdn
[3] lnk-sttc
[4] gcc-11/rls/abi-apcs/archt-arm/bst.l-lbc/bst.l-on/bst.l-off/bld-no/lnk-sttc/nm-on/pythn-3.10/thrdp-pthrd/thrd-mlt/vsblt-hdn

Component configuration:

    - atomic                   : building
    - chrono                   : building
    - container                : building
    - context                  : building
    - contract                 : building
    - coroutine                : building
    - date_time                : building
    - exception                : building
    - fiber                    : building
    - filesystem               : building
    - graph                    : building
    - graph_parallel           : not building
    - headers                  : not building
    - iostreams                : building
    - json                     : building
    - locale                   : building
    - log                      : building
    - math                     : building
    - mpi                      : not building
    - nowide                   : building
    - program_options          : building
    - python                   : not building
    - random                   : building
    - regex                    : building
    - serialization            : building
    - stacktrace               : building
    - system                   : building
    - test                     : building
    - thread                   : building
    - timer                    : building
    - type_erasure             : building
    - url                      : building
    - wave                     : building

make_arm64_aapcs_elf_gas.S: Assembler messages:
make_arm64_aapcs_elf_gas.S:61: Error: too many memory references for `and'
make_arm64_aapcs_elf_gas.S:64: Error: too many memory references for `sub'
make_arm64_aapcs_elf_gas.S:68: Error: too many memory references for `str'
make_arm64_aapcs_elf_gas.S:72: Error: no such instruction: `adr x1,finish'
make_arm64_aapcs_elf_gas.S:73: Error: too many memory references for `str'
make_arm64_aapcs_elf_gas.S:75: Error: unsupported syntax for `ret'
make_arm64_aapcs_elf_gas.S:79: Error: expecting operand after ','; got nothing
make_arm64_aapcs_elf_gas.S:81: Error: no such instruction: `bl _exit'
...failed updating 1 target...
boost/1.81.0: 
boost/1.81.0: ERROR: Package '3aac81ffa04cca0028f0506d5a46ab398161b6d4' build failed
boost/1.81.0: WARN: Build folder /home/gyd/.conan/data/boost/1.81.0/_/_/build/3aac81ffa04cca0028f0506d5a46ab398161b6d4/build-release
ERROR: boost/1.81.0: Error in build() method, line 887
	self.run(full_command)
	ConanException: Error 1 while executing b2 -q numa=on target-os=linux architecture=arm address-model=64 binary-format=elf abi=aapcs --layout=system --user-config=/home/gyd/.conan/data/boost/1.81.0/_/_/source/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-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=gcc define=_GLIBCXX_USE_CXX11_ABI=1 pch=on -sLIBBACKTRACE_PATH=/home/gyd/.conan/data/libbacktrace/cci.20210118/_/_/package/8fd38d381db52e2495321ce060b9f457656f6c8f linkflags="" cxxflags="-fPIC -DBOOST_STACKTRACE_ADDR2LINE_LOCATION=/usr/bin/addr2line" install --prefix=/home/gyd/.conan/data/boost/1.81.0/_/_/package/3aac81ffa04cca0028f0506d5a46ab398161b6d4 -j4 --abbreviate-paths -d0 --debug-configuration --build-dir="/home/gyd/.conan/data/boost/1.81.0/_/_/build/3aac81ffa04cca0028f0506d5a46ab398161b6d4/build-release"

从后面这段可以看出是编译器在编译arm64汇编代码时出错了
在这里插入图片描述
如果编译器设置正确应该不会出现这个错误,于是从输出日志再往上找我又找到了这段
在这里插入图片描述
果然是使用本机编译器g++而不是交叉编译器 aarch64-linux-gnu-g++

boost是由b2执行编译的,使用哪个编译器由环境变量CC来决定,CC定义在profile,所以问题应该出在profile.

如下是执行aarch64-linux-gnu交叉编译使用的profile,
aarch64-linux-gnu.jinja

include(default)
target_host=aarch64-linux-gnu
[settings]
arch=armv8
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=5.4
os=Linux
[options]
[env]
CHOST=$target_host
CC=$target_host-gcc
CXX=$target_host-g++
AR=$target_host-ar
AS=$target_host-as
RANLIB=$target_host-ranlib
LD=$target_host-ld
STRIP=$target_host-strip
#########################################################################################
# 指定./conan/cmake/aarch64-linux-gnu.toolchain.cmake 为cmake 工具链文件             #
#########################################################################################
{% set toolchain = os.path.join(profile_dir, "..","cmake","aarch64-linux-gnu.toolchain.cmake") %}
CONAN_CMAKE_TOOLCHAIN_FILE={{ toolchain }}
CONAN_CMAKE_GENERATOR="Unix Makefiles"

这个profile是我一年前写的,当时可以正确执行交叉编译,当然了,那个时候使用的conan 版本是1.45.0,一年多过去了,conan的版本迭代很快,目前我使用的是conan 1.x的接近最新版本1.60.0(1.x下当前最新版本是1.60.2),
会不会是因为版本更新来带的兼容性问题呢?
打开conan官方文档profile相关的页面 https://docs.conan.io/1/reference/profiles.html
第一眼就看到了这个
在这里插入图片描述
原来profile中的[env]字段名被废弃了,改为了[buildenv],
再看[buildenv]的说明:从1.35.0开始新增加了这个字段,用于替换[env]
在这里插入图片描述

立即把上面aarch64-linux-gnu.jinja profile中的[env]改为[buildenv]再如下执行boost交叉编译通过

conan install boost/1.81.0@ -pr:h aarch64-linux-gnu.jinja -pr:b default --build boost

conan系列文章

《conan入门(一):conan 及 JFrog Artifactory 安装》
《conan入门(二):conan 服务配置-密码管理及策略》
《conan入门(三):上传预编译的库(artifact)》
《conan入门(四):conan 引用第三方库示例》
《conan入门(五):conan 交叉编译引用第三方库示例》
《conan入门(六):conanfile.txt conanfile.py的区别》
《conan入门(七):将自己的项目生成conan包》
《conan入门(八):交叉编译自己的conan包项目》
《conan入门(九):NDK交叉编译自己的conan包项目塈profile的定义》
《conan入门(十):Windows下Android NDK交叉编译Boost》
《conan入门(十一):Linux下Android NDK交叉编译Boost》
《conan入门(十二):Windows NDK 编译 boost报错:CMake was unable to find a build program … MinGW Makefile》
《conan入门(十三):conan info 命令的基本用法》
《conan入门(十四):conan new 命令的新特性–模板功能(–template)》
《conan入门(十五):AttributeError: ‘CMake‘ object has no attribute ‘definitions‘》
《conan入门(十六):profile template功能实现不同平台下profile的统一》
《conan入门(十七):支持android NDK (armv7,armv8,x86,x86_64)交叉编译的统一profile jinja2模板》
《conan入门(十八):Cannot recognize the Windows subsystem, install MSYS2/cygwin or specify a build_require》
《conan入门(十九):封装第三方开源库cpp_redis示例》
《conan入门(二十):封装只包含头文件(header_only)的库示例》
《conan入门(二十一):解决MinGW编译Openssl的编译错误:crypto/dso/dso_win32.c》
《conan入门(二十二):编译 openssl要求python 3.7以上版本》
《conan入门(二十三):Windows下MinGW编译libcurl》
《conan入门(二十四):通过CONAN_DISABLE_CHECK_COMPILER禁用编译器检查》
《conan入门(二十五):imports将包安装到本地项目或其他指定位置》
《conan入门(二十六):使用make编译makefile》
《conan入门(二十七):因profile [env]字段废弃导致的boost/1.81.0 在aarch64-linux-gnu下交叉编译失败》
《conan入门(二十八):解决conan 1.60.0下 arch64-linux-gnu交叉编译openssl/3.1.2报错问题》
《conan入门(二十九):对第三方库mnn进行Conan封装塈conans.CMake和conan.tools.cmake.CMake的区别》
《conan入门(三十):对腾讯ncnn进行Conan封装》
《conan入门(三十一):在命令行(shell)中从profile中读取配置参数》
《conan 入门(三十二):package_info中配置禁用CMakeDeps生成使用项目自己生成的config.cmake》
《conan 入门(三十三):requirements()指定header的可见性(transitive_headers)》
《conan 入门(三十四):conan 2.x实现对只有Makefile的项目(erpcgen)的封装示例》
《conan 入门(三十五):在conanfile.py中获取C++编译器完整路径的方法》
《conan入门(三十六):在set_version方法中从pom.xml中读取版本号实现动态版本定义》
《conan 入门(三十七):conan 2.x通过定义环境变量(environment)执行make编译只有Makefile的项目(erpcgen)》
《conan 入门(三十八):conan二进制包的兼容性及自定义package_id的方式》
《conan入门(三十九):conan 2.x 引用第三方库示例》

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
您好,我是 ChitGPT。 关于您的问题,以下是一个示例的 CMakeLists.txt 文件: ```cmake cmake_minimum_required(VERSION 3.10) project(DeviceMain) add_executable(device_main device_main.cpp) target_link_libraries(device_main PRIVATE ${CONAN_LIBS}) if (CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Linux") # Use the cross-compilation toolchain file include(cmake/toolchains/arm-linux-gnueabihf.cmake) # Add the strip command as a custom target add_custom_target( strip_device_main COMMAND ${CMAKE_STRIP} -s $<TARGET_FILE:device_main> ) # Build the device_main executable with the toolchain set(CMAKE_CXX_STANDARD 11) target_compile_options(device_main PRIVATE -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard) target_link_options(device_main PRIVATE -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -Wl,-rpath-link,/usr/arm-linux-gnueabihf/lib) # Strip the executable after building add_dependencies(device_main strip_device_main) endif() ``` 其中,您需要根据您的具体需求修改以下部分: - `project(DeviceMain)`:将 `DeviceMain` 替换为您的项目名称。 - `add_executable(device_main device_main.cpp)`:将 `device_main` 替换为您的可执行文件名称,将 `device_main.cpp` 替换为您可执行文件的源代码文件名。 - `target_link_libraries(device_main PRIVATE ${CONAN_LIBS})`:如果您使用了 Conan 包管理器,将 `${CONAN_LIBS}` 替换为您需要链接的库名称,否则将其删除。 - `include(cmake/toolchains/arm-linux-gnueabihf.cmake)`:将 `arm-linux-gnueabihf.cmake` 替换为您实际使用的交叉编译器工具链文件名。 - `COMMAND ${CMAKE_STRIP} -s $<TARGET_FILE:device_main>`:将 `device_main` 替换为您的可执行文件名称。 希望这能对您有所帮助!如有其他问题,请随时提出。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

10km

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值