conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
966 stars 1.77k forks source link

[Cross compiling boost 1.81.0 fails] Fails to link boosturl #16695

Closed av4625 closed 1 year ago

av4625 commented 1 year ago

Environment details

Steps to reproduce

set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR})

if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/conan.cmake")
    message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
    file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.1/conan.cmake"
        "${CMAKE_CURRENT_BINARY_DIR}/conan.cmake"
        TLS_VERIFY ON)
endif()

include(${CMAKE_CURRENT_BINARY_DIR}/conan.cmake)

set(LIBS boost/1.81.0)

set(LIBS_OPTIONS
    boost:without_atomic=False
    boost:without_chrono=False
    boost:without_container=False
    boost:without_context=True
    boost:without_contract=True
    boost:without_coroutine=True
    boost:without_date_time=False
    boost:without_exception=False
    boost:without_fiber=True
    boost:without_filesystem=True
    boost:without_graph=True
    boost:without_graph_parallel=True
    boost:without_iostreams=True
    boost:without_json=True
    boost:without_locale=True
    boost:without_log=True
    boost:without_math=True
    boost:without_mpi=True
    boost:without_nowide=True
    boost:without_program_options=True
    boost:without_python=True
    boost:without_random=True
    boost:without_regex=True
    boost:without_serialization=True
    boost:without_stacktrace=True
    boost:without_system=False
    boost:without_test=True
    boost:without_thread=False
    boost:without_timer=True
    boost:without_type_erasure=True
    boost:without_url=False
    boost:without_wave=True
    boost:visibility=global)

conan_cmake_configure(
    REQUIRES ${LIBS}
    GENERATORS cmake_find_package
    OPTIONS
    ${LIBS_OPTIONS})

conan_cmake_autodetect(build_settings)

if (NOT DEVICE STREQUAL "OrangePi")
    set(CONAN_INSTALL_DATA SETTINGS ${build_settings})
else()
    set(host_settings
        os=Linux
        os_build=Linux
        arch=armv7
        arch_build=armv7
        compiler=gcc
        compiler.version=11.3
        compiler.libcxx=libstdc++11
        compiler.cppstd=17
        build_type=${CMAKE_BUILD_TYPE})

    set(host_env
        CHOST=arm-linux-gnueabihf
        CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM=${CMAKE_FIND_ROOT_PATH_MODE_PROGRAM}
        CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=${CMAKE_FIND_ROOT_PATH_MODE_LIBRARY}
        CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE=${CMAKE_FIND_ROOT_PATH_MODE_INCLUDE}
        CONAN_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=${CMAKE_FIND_ROOT_PATH_MODE_PACKAGE}
        AR=${CMAKE_AR}
        AS=${CMAKE_ASM_COMPILER}
        RANLIB=${CMAKE_RANLIB}
        LD=${CMAKE_LINKER}
        STRIP=${CMAKE_STRIP}
        CC=${CMAKE_C_COMPILER}
        CXX=${CMAKE_CXX_COMPILER})

    set(CONAN_INSTALL_DATA
        SETTINGS_BUILD ${build_settings}
        SETTINGS_HOST ${host_settings}
        ENV_HOST ${host_env})
endif()

conan_cmake_install(
    PATH_OR_REFERENCE .
    BUILD missing
    REMOTE conancenter
    ${CONAN_INSTALL_DATA})

find_package(
    Boost 1.81.0
    EXACT REQUIRED COMPONENTS
    thread
    url
    REQUIRED GLOBAL)

This is how I include boost in my project. It works fine if I am compiling for the native system (not OrangePi). But when I try to cross compile (for OrangePi) I get the error below when it tries to link boosturl.

As b2 is needed, I'm not sure if it is correctly using the cross compiler when building it from the output.

Logs

You will see I also have gtest and nlohmann_json, I removed these from this post as they build correctly.

cmake command

-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/arm-linux-gnueabihf-gcc-11 - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabihf-g++-11 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Downloading conan.cmake from https://github.com/conan-io/cmake-conan
-- Conan: checking conan executable
-- Conan: Found program /usr/local/bin/conan
-- Conan: Version found Conan version 1.59.0
-- Conan executing: /usr/local/bin/conan install . --remote conancenter --build missing --env:host CHOST=arm-linux-gnueabihf --env:host CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER --env:host CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY --env:host CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY --env:host CONAN_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY --env:host AR=arm-linux-gnueabihf-ar --env:host AS=arm-linux-gnueabihf-as --env:host RANLIB=arm-linux-gnueabihf-ranlib --env:host LD=/usr/bin/arm-linux-gnueabihf-ld --env:host STRIP=arm-linux-gnueabihf-strip --env:host CC=/usr/bin/arm-linux-gnueabihf-gcc-11 --env:host CXX=/usr/bin/arm-linux-gnueabihf-g++-11 --settings:host os=Linux --settings:host os_build=Linux --settings:host arch=armv7 --settings:host arch_build=armv7 --settings:host compiler=gcc --settings:host compiler.version=11.3 --settings:host compiler.libcxx=libstdc++11 --settings:host compiler.cppstd=17 --settings:host build_type=Release --settings:build build_type=Release --settings:build compiler=gcc --settings:build compiler.version=11 --settings:build compiler.libcxx=libstdc++11 --settings:build compiler.cppstd=17
Configuration (profile_host):
[settings]
arch=armv7
arch_build=armv7
build_type=Release
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=11.3
os=Linux
os_build=Linux
[options]
[build_requires]
[env]
AR=arm-linux-gnueabihf-ar
AS=arm-linux-gnueabihf-as
CC=/usr/bin/arm-linux-gnueabihf-gcc-11
CHOST=arm-linux-gnueabihf
CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY
CONAN_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY
CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
CXX=/usr/bin/arm-linux-gnueabihf-g++-11
LD=/usr/bin/arm-linux-gnueabihf-ld
RANLIB=arm-linux-gnueabihf-ranlib
STRIP=arm-linux-gnueabihf-strip
[buildenv]
CC=gcc
CXX=g++

Configuration (profile_build):
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=11
os=Linux
os_build=Linux
[options]
[build_requires]
[env]
CC=gcc
CXX=g++
[buildenv]
CC=gcc
CXX=g++

gtest/1.12.1: Retrieving from server 'conancenter'
gtest/1.12.1: Trying with 'conancenter'...
Downloading conanmanifest.txt
Downloading conanfile.py
Downloading conan_export.tgz
gtest/1.12.1: Downloaded recipe revision 0
boost/1.81.0: Retrieving from server 'conancenter'
boost/1.81.0: Trying with 'conancenter'...
Downloading conanmanifest.txt
Downloading conanfile.py
Downloading conan_export.tgz
boost/1.81.0: Downloaded recipe revision 0
nlohmann_json/3.11.2: Retrieving from server 'conancenter'
nlohmann_json/3.11.2: Trying with 'conancenter'...
Downloading conanmanifest.txt
Downloading conanfile.py
Downloading conan_export.tgz
nlohmann_json/3.11.2: Downloaded recipe revision 0
b2/4.9.3: Retrieving from server 'conancenter'
b2/4.9.3: Trying with 'conancenter'...
Downloading conanmanifest.txt
Downloading conanfile.py
Downloading conan_export.tgz
b2/4.9.3: Downloaded recipe revision 0
conanfile.txt: Installing package
Requirements
    boost/1.81.0 from 'conancenter' - Downloaded
    gtest/1.12.1 from 'conancenter' - Downloaded
    nlohmann_json/3.11.2 from 'conancenter' - Downloaded
Packages
    boost/1.81.0:93a617ae865233fe06a96c2acf7843b42f0fea05 - Build
    gtest/1.12.1:82042c4a7e8627082d8732454220ac7ae2131c71 - Build
    nlohmann_json/3.11.2:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Download
Build requirements
    b2/4.9.3 from 'conancenter' - Downloaded
Build requirements packages
    b2/4.9.3:4db1be536558d833e52e862fd84d64d75c2b3656 - Download

Cross-build from 'Linux:x86_64' to 'Linux:armv7'
Installing (downloading, building) binaries...
b2/4.9.3: Retrieving package 4db1be536558d833e52e862fd84d64d75c2b3656 from remote 'conancenter'
Downloading conanmanifest.txt
Downloading conaninfo.txt
Downloading conan_package.tgz
b2/4.9.3: Package installed 4db1be536558d833e52e862fd84d64d75c2b3656
b2/4.9.3: Downloaded package revision 0

...

boost/1.81.0: Applying build-requirement: b2/4.9.3
Downloading conan_sources.tgz
boost/1.81.0: Configuring sources in /home/avance/.conan/data/boost/1.81.0/_/_/source/src
boost/1.81.0: .boost/1.81.0:
boost/1.81.0: Apply patch (conan): Fails the build when mpi is not configured
boost/1.81.0: Apply patch (conan): Fails the build when there is no iconv backend
boost/1.81.0: Building your package in /home/avance/.conan/data/boost/1.81.0/_/_/build/93a617ae865233fe06a96c2acf7843b42f0fea05
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 '/* thread_local */' in '/home/avance/.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/avance/.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/avance/.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/avance/.conan/data/boost/1.81.0/_/_/source/src/tools/build/src/tools/gcc.jam' file.
boost/1.81.0: WARN: Patching user-config.jam
boost/1.81.0: WARN:
using "gcc" :  :  "g++" :
 ;
boost/1.81.0: Cross building, detecting compiler...
boost/1.81.0: Cross building flags: []
boost/1.81.0: WARN: b2 -q target-os=linux architecture=arm address-model=32 binary-format=elf abi=aapcs --layout=system --user-config=/home/avance/.conan/data/boost/1.81.0/_/_/source/src/tools/build/user-config.jam -sNO_ZLIB=1 -sNO_BZIP2=1 -sNO_LZMA=1 -sNO_ZSTD=1 boost.locale.icu=off --disable-icu boost.locale.iconv=off --disable-iconv threading=multi visibility=global link=static variant=release --with-atomic --with-chrono --with-container --with-date_time --with-exception --with-system --with-thread --with-url toolset=gcc cxxflags=-std=c++17 define=_GLIBCXX_USE_CXX11_ABI=1 pch=on linkflags="" cxxflags="-fPIC" install --prefix=/home/avance/.conan/data/boost/1.81.0/_/_/package/93a617ae865233fe06a96c2acf7843b42f0fea05 -j4 --abbreviate-paths -d0 --debug-configuration --build-dir="/home/avance/.conan/data/boost/1.81.0/_/_/build/93a617ae865233fe06a96c2acf7843b42f0fea05/build-release"
notice: found boost-build.jam at /home/avance/.conan/data/boost/1.81.0/_/_/source/src/boost-build.jam
notice: loading B2 from /home/avance/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/kernel/bootstrap.jam
notice: Searching '/etc' '/home/avance' '/home/avance/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/kernel' '/home/avance/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/util' '/home/avance/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/build' '/home/avance/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/tools' '/home/avance/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/contrib' '/home/avance/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/.' for site-config configuration file 'site-config.jam'.
notice: Configuration file 'site-config.jam' not found in '/etc' '/home/avance' '/home/avance/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/kernel' '/home/avance/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/util' '/home/avance/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/build' '/home/avance/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/tools' '/home/avance/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/contrib' '/home/avance/.conan/data/b2/4.9.3/_/_/package/4db1be536558d833e52e862fd84d64d75c2b3656/bin/.b2/.'.
notice: Loading explicitly specified user configuration file:
    /home/avance/.conan/data/boost/1.81.0/_/_/source/src/tools/build/user-config.jam
notice: Searching '/home/avance/.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/avance/.conan/data/boost/1.81.0/_/_/source/src/tools/build'.
notice: will use '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/avance/.conan/data/boost/1.81.0/_/_/source/src/tools/build/user-config.jam:3
notice: using rc compiler :: <toolset>gcc-11 :: /usr/bin/as
notice: iostreams: not using zlib compression
notice: iostreams: not using bzip compression
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] ...does not invoke a working interpreter
notice: [python-cfg] Python headers and libraries not found.
Performing configuration checks

    - default address-model    : 64-bit [1]
    - default architecture     : x86 [1]
    - lockfree boost::atomic_flag : yes [2]
    - cxx11_constexpr          : yes [2]
    - cxx11_decltype           : yes [2]
    - cxx11_hdr_tuple          : yes [2]
    - cxx11_template_aliases   : yes [2]
    - cxx11_variadic_templates : yes [2]

[1] gcc-11
[2] gcc-11/rls/abi-apcs/adrs-mdl-32/archt-arm/bst.l-off/bst.l-off/lnk-sttc/thrdp-pthrd/thrd-mlt/vsblt-glbl

Component configuration:

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

boost/1.81.0: Package '93a617ae865233fe06a96c2acf7843b42f0fea05' built
boost/1.81.0: Build folder /home/avance/.conan/data/boost/1.81.0/_/_/build/93a617ae865233fe06a96c2acf7843b42f0fea05/build-release
boost/1.81.0: Generated conaninfo.txt
boost/1.81.0: Generated conanbuildinfo.txt
boost/1.81.0: Generating the package
boost/1.81.0: Package folder /home/avance/.conan/data/boost/1.81.0/_/_/package/93a617ae865233fe06a96c2acf7843b42f0fea05
boost/1.81.0: Calling package()
boost/1.81.0: Copied 1 '.txt' file: LICENSE_1_0.txt
boost/1.81.0 package(): Packaged 8 '.a' files
boost/1.81.0 package(): Packaged 1 '.txt' file: LICENSE_1_0.txt
boost/1.81.0 package(): Packaged 14939 '.hpp' files
boost/1.81.0 package(): Packaged 148 '.h' files
boost/1.81.0 package(): Packaged 2 '.inc' files: cpp_re.inc, strict_cpp_re.inc
boost/1.81.0 package(): Packaged 341 '.ipp' files
boost/1.81.0 package(): Packaged 17 files
boost/1.81.0: Package '93a617ae865233fe06a96c2acf7843b42f0fea05' created
boost/1.81.0: Created package revision a35f5422a55a9096c340ab8a60b43a00

build command

/usr/lib/gcc-cross/arm-linux-gnueabihf/11/../../../../arm-linux-gnueabihf/bin/ld: /home/user/.conan/data/boost/1.81.0/_/_/package/93a617ae865233fe06a96c2acf7843b42f0fea05/lib/libboost_url.a: error adding symbols: file format not recognized
collect2: error: ld returned 1 exit status
av4625 commented 1 year ago

When building gtest using this method the output from objdump is:

$ arm-linux-gnueabihf-objdump -x /home/user/.conan/data/gtest/1.12.1/_/_/package/82042c4a7e8627082d8732454220ac7ae2131c71/lib/libgtest.a | grep architecture | head -n 1
architecture: armv7, flags 0x00000011:
$ objdump -x /home/user/.conan/data/gtest/1.12.1/_/_/package/82042c4a7e8627082d8732454220ac7ae2131c71/lib/libgtest.a | grep architecture | head -n 1
architecture: UNKNOWN!, flags 0x00000011:

This is the output from boost:

$ arm-linux-gnueabihf-objdump -x /home/user/.conan/data/boost/1.81.0/_/_/package/93a617ae865233fe06a96c2acf7843b42f0fea05/lib/libboost_url.a | grep architecture | head -n 1
arm-linux-gnueabihf-objdump: src.o: file format not recognized
$ arm-linux-gnueabihf-objdump -x /home/user/.conan/data/boost/1.81.0/_/_/package/93a617ae865233fe06a96c2acf7843b42f0fea05/lib/libboost_thread.a | grep architecture | head -n 1
arm-linux-gnueabihf-objdump: thread.o: file format not recognized
arm-linux-gnueabihf-objdump: once.o: file format not recognized
arm-linux-gnueabihf-objdump: future.o: file format not recognized
$ objdump -x /home/user/.conan/data/boost/1.81.0/_/_/package/93a617ae865233fe06a96c2acf7843b42f0fea05/lib/libboost_url.a | grep architecture | head -n 1
architecture: i386:x86-64, flags 0x00000011:
$ objdump -x /home/user/.conan/data/boost/1.81.0/_/_/package/93a617ae865233fe06a96c2acf7843b42f0fea05/lib/libboost_thread.a | grep architecture | head -n 1
architecture: i386:x86-64, flags 0x00000011:

Looks like boost is not using the cross compiler but is using the system compiler. I think b2 is doing the same.

av4625 commented 1 year ago

I have tried taking the conan cmake wrapper out of the equation.

I used these profiles: Host

[settings]
os=Linux
os_build=Linux
arch=armv7hf
arch_build=armv7hf
build_type=Release
compiler=gcc
compiler.version=11.3
compiler.libcxx=libstdc++11
compiler.cppstd=17
[options]
[build_requires]
[env]
CHOST=arm-linux-gnueabihf
CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY
CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
CONAN_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY
AR=arm-linux-gnueabihf-ar
AS=arm-linux-gnueabihf-as
RANLIB=arm-linux-gnueabihf-ranlib
LD=arm-linux-gnueabihf-ld
STRIP=arm-linux-gnueabihf-strip
CC=arm-linux-gnueabihf-gcc-11
CXX=arm-linux-gnueabihf-g++-11
[buildenv]
CHOST=arm-linux-gnueabihf
CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY
CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
CONAN_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY
AR=arm-linux-gnueabihf-ar
AS=arm-linux-gnueabihf-as
RANLIB=arm-linux-gnueabihf-ranlib
LD=arm-linux-gnueabihf-ld
STRIP=arm-linux-gnueabihf-strip
CC=arm-linux-gnueabihf-gcc-11
CXX=arm-linux-gnueabihf-g++-11

Build

[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.version=11.3
compiler.libcxx=libstdc++11
compiler.cppstd=17
[options]
[build_requires]
[env]
CC=gcc
CXX=g++
[buildenv]
CC=gcc
CXX=g++

I run this command:

conan install -r conancenter boost/1.81.0@ -pr:b=default -pr:h=orangepi --update --build missing

I get this error:

boost/1.81.0: ERROR: Package '03a1da9efd1499075af320e65aa68e212d39ae33' build failed
boost/1.81.0: WARN: Build folder /home/user/.conan/data/boost/1.81.0/_/_/build/03a1da9efd1499075af320e65aa68e212d39ae33/build-release
ERROR: boost/1.81.0: Error in build() method, line 880
        self.run(full_command)
        ConanException: Error 1 while executing b2 -mfloat-abi=hard -q numa=on target-os=linux architecture=arm address-model=32 binary-format=elf abi=aapcs --layout=system --user-config=/home/user/.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 cxxflags=-std=c++17 define=_GLIBCXX_USE_CXX11_ABI=1 pch=on -sLIBBACKTRACE_PATH=/home/user/.conan/data/libbacktrace/cci.20210118/_/_/package/5cc1d3891344069b65da13c045ea49880c271674 linkflags="" cxxflags="-fPIC -DBOOST_STACKTRACE_ADDR2LINE_LOCATION=/usr/bin/addr2line" install --prefix=/home/user/.conan/data/boost/1.81.0/_/_/package/03a1da9efd1499075af320e65aa68e212d39ae33 -j4 --abbreviate-paths -d0 --debug-configuration --build-dir="/home/user/.conan/data/boost/1.81.0/_/_/build/03a1da9efd1499075af320e65aa68e212d39ae33/build-release"

Tried adding buildenv that other issues talk about but it didn't help

lukasberbuer commented 1 year ago

I ran into the same issue. @av4625 did you find a fix or workaround?

jcar87 commented 1 year ago

Hi @av4625 and @lukasberbuer - thanks for the detailed report.

is the issue exclusive to boosturl or does it happen with other components when cross-building?

lukasberbuer commented 1 year ago

Yes, cross-building of my other requirements (spdlog, catch2, openssl, zlib, ...) seems to work.

Edit: It's the same issue for all compiled boost libraries

Test with objdump:


$ arm-linux-gnueabihf-objdump -x ~/.conan/data/spdlog/1.11.0/_/_/package/.../lib/libspdlog.a | grep architecture | head -n 1
architecture: armv7, flags 0x00000011:

$ arm-linux-gnueabihf-objdump -x ~/.conan/data/boost/1.80.0/_/_/package/.../lib/libboost_program_options.a | grep architecture | head -n 1
arm-linux-gnueabihf-objdump: cmdline.o: file format not recognized
arm-linux-gnueabihf-objdump: config_file.o: file format not recognized
arm-linux-gnueabihf-objdump: options_description.o: file format not recognized
arm-linux-gnueabihf-objdump: parsers.o: file format not recognized
arm-linux-gnueabihf-objdump: variables_map.o: file format not recognized
arm-linux-gnueabihf-objdump: value_semantic.o: file format not recognized
arm-linux-gnueabihf-objdump: positional_options.o: file format not recognized
arm-linux-gnueabihf-objdump: utf8_codecvt_facet.o: file format not recognized
arm-linux-gnueabihf-objdump: convert.o: file format not recognized
arm-linux-gnueabihf-objdump: winmain.o: file format not recognized
arm-linux-gnueabihf-objdump: split.o: file format not recognized
jcar87 commented 1 year ago

I see, thanks!! I'll try to reproduce :)

lukasberbuer commented 1 year ago

Just found some hints in the logs why boost is falling back to another compiler 😕

boost/1.80.0: WARN: Patching user-config.jam
boost/1.80.0: WARN: Using the new toolchains and generators without specifying a build profile (e.g: -pr:b=default) is discouraged and might cause failures and unexpected behavior
boost/1.80.0: WARN: 
using "gcc" :  :  "/usr/bin/g++" :
 ;
notice: Searching '/home/lb/.conan/data/boost/1.80.0/_/_/source/src/tools/build' for user-config configuration file 'user-config.jam'.
notice: Loading user-config configuration file 'user-config.jam' from '/home/lb/.conan/data/boost/1.80.0/_/_/source/src/tools/build'.
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
jcar87 commented 1 year ago

@lukasberbuer - I can see the logic where this is set - I'm surprised it doesn't honour the CXX variable t hat you set in the [buildenv] section.

Could you try adding the following to your host profile and then attempt the build again?

[conf]
tools.build:compiler_executables={"cpp": "arm-linux-gnueabihf-g++-11", "c": "arm-linux-gnueabihf-gcc-11"}
av4625 commented 1 year ago

@jcar87 This comment also shows me showing the output for boost thread as well as url and both are the same: https://github.com/conan-io/conan-center-index/issues/16695

I too am seeing this: https://github.com/conan-io/conan-center-index/issues/16695

I will try and find some time soon to try your suggestion!

@lukasberbuer the only work around I have found currently (and its terrible) is to do a native build on the arm machine. Tar everything in the conan boost package directory. Then do my cross compiled build and replace the package directory with the one I tarred from the arm device. Defeats the purpose of using conan though. My arm device doesn't have a lot of ram so took hours to build and failed a few times as it ran out of ram :(

jcar87 commented 1 year ago

Tahnks @av4625 - same thing, if you could try adding that conf I mentioned above to your host profile, and report back, that would be great - in the meantime I'll review the logic to retrieve it from the CC/CXX variables!

thanks!

lukasberbuer commented 1 year ago

Thanks @jcar87! As suggested, I just added following to the host profile:

[conf]
tools.build:compiler_executables={"cpp": "arm-linux-gnueabihf-g++-11", "c": "arm-linux-gnueabihf-gcc-11"}

I still get the same errors as described above, but maybe the log messages are interesting:

notice: will use 'arm-linux-gnueabihf-g++-11' 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 :: arm-linux-gnueabihf-ar
warning: toolset gcc initialization: can not find tool windres
jcar87 commented 1 year ago

I've had a further chance to look into this.

@av4625, your original issue (with cmake-conan), stems from the details in the host profile, as per your first post:

Configuration (profile_host):
[settings]
arch=armv7
arch_build=armv7
build_type=Release
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=11.3
os=Linux
os_build=Linux
[options]
[build_requires]
[env]
AR=arm-linux-gnueabihf-ar
AS=arm-linux-gnueabihf-as
CC=/usr/bin/arm-linux-gnueabihf-gcc-11
CHOST=arm-linux-gnueabihf
CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY
CONAN_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY
CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
CXX=/usr/bin/arm-linux-gnueabihf-g++-11
LD=/usr/bin/arm-linux-gnueabihf-ld
RANLIB=arm-linux-gnueabihf-ranlib
STRIP=arm-linux-gnueabihf-strip
[buildenv]
CC=gcc
CXX=g++

the [buildenv] section is setting the CC and CXX variables to what's presumably your local native compiler - that's what the recipe is set to honour, and thus that's why the x86_64 compiler is used.

When invoking conan directly as per your comment here: https://github.com/conan-io/conan-center-index/issues/16695#issuecomment-1483363508 - I am able to build it just fine with the correct architecture - although I've used a compiler targetting aarch64:

[settings]
os=Linux
arch=armv8
compiler=gcc
compiler.version=11
compiler.libcxx=libstdc++11
build_type=Release

[buildenv]
CHOST=aarch64-linux-gnu
AR=aarch64-linux-gnu-ar
AS=aarch64-linux-gnu-as
RANLIB=aarch64-linux-gnu-ranlib
LD=aarch64-linux-gnu-ld
STRIP=aarch64-linux-gnu-strip
CC=aarch64-linux-gnu-gcc-11
CXX=aarch64-linux-gnu-g++-11

In your case you'd have to replace aarch64-linux-gnu- with arm-linux-gnueabihf-, as well as changing the arch / version if it applies.

The relevant part of the build prints this for me, with a successful build afterwards:

notice: will use 'aarch64-linux-gnu-g++-11' 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 :: aarch64-linux-gnu-ar
warning: toolset gcc initialization: can not find tool windres
warning: initialized from /home/julius/.conan/data/boost/1.81.0/_/_/source/src/tools/build/user-config.jam:5
notice: using rc compiler :: <toolset>gcc-11 :: /usr/bin/as

@av4625, @lukasberbuer, may I suggest:

git clone https://github.com/conan-io/conan-center-index.git
cd conan-center-index
conan create recipes/boost/all 1.81.0@ --profile:host your_host_profile --profile:build default -o"boost:debug_level=1" 

If you could attach the entire output of running the command as above, I will investigate further, cheers!

av4625 commented 1 year ago

@jcar87 thanks, I will give that a go. I decided to remove cmake-conan from the equation as I wasn't sure how to add the buildenv section

av4625 commented 1 year ago

I got the same problem as I did here: https://github.com/conan-io/conan-center-index/issues/16695#issuecomment-1483363508

I had to add --build=missing to your command. output.txt

Edit: Do you know how to set the [buildenv] section using cmake-conan in the conan_cmake_install command?

lukasberbuer commented 1 year ago

Thanks for diving deep @jcar87! I tried your steps with the same results as @av4625:

~/.conan/profiles/default:

[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=11
compiler.libcxx=libstdc++11
build_type=Release
[options]
[build_requires]
[env]

~/.conan/profiles/armv7:

[settings]
os=Linux
arch=armv7
compiler=gcc
compiler.version=11
compiler.libcxx=libstdc++11
build_type=Release

[buildenv]
CHOST=arm-linux-gnueabihf
AR=arm-linux-gnueabihf-ar
AS=arm-linux-gnueabihf-as
RANLIB=arm-linux-gnueabihf-ranlib
LD=arm-linux-gnueabihf-ld
STRIP=arm-linux-gnueabihf-strip
CC=arm-linux-gnueabihf-gcc-11
CXX=arm-linux-gnueabihf-g++-11

Output of conan create recipes/boost/all 1.81.0@ --profile:host armv7 --profile:build default -o"boost:debug_level=1": output_conan_center_index.txt

jcar87 commented 1 year ago

Hi @lukasberbuer and @av4625 - thank you for running the command and attaching your build logs.

The good news is that I can see the build appears correctly configured to cross-build Boost for ARM.

The bad news is that it is failing for something specific to 32-bit ARM:

gcc.compile.asm /home/lb/.conan/data/boost/1.81.0/_/_/build/ee88e4e78fdd19f4c17bdc0968692568847a4988/build-release/boost/bin.v2/libs/context/build/gcc-11/rls/abi-apcs/lnk-sttc/nm-on/thrd-mlt/vsblt-hdn/asm/jump_arm_aapcs_elf_gas.o
jump_arm_aapcs_elf_gas.S: Assembler messages:
jump_arm_aapcs_elf_gas.S:57: Error: selected processor does not support `vstmia sp,{d8-d15}' in ARM mode
jump_arm_aapcs_elf_gas.S:68: Error: selected processor does not support `vldmia sp,{d8-d15}' in ARM mode

    "arm-linux-gnueabihf-g++-11" -x assembler-with-cpp -pthread -O3 -finline-functions -Wno-inline -Wall -fvisibility=hidden -I/home/lb/.conan/data/libbacktrace/cci.20210118/_/_/package/2d7ebe5aec211724d06c7670bb80889f73c8ff36/include  -DBOOST_ALL_NO_LIB=1 -DBOOST_CONTEXT_SOURCE -DBOOST_DISABLE_ASSERTS -DBOOST_USE_NUMA -DNDEBUG -D_GLIBCXX_USE_CXX11_ABI=1 -I"." -c -o "/home/lb/.conan/data/boost/1.81.0/_/_/build/ee88e4e78fdd19f4c17bdc0968692568847a4988/build-release/boost/bin.v2/libs/context/build/gcc-11/rls/abi-apcs/lnk-sttc/nm-on/thrd-mlt/vsblt-hdn/asm/jump_arm_aapcs_elf_gas.o" "libs/context/src/asm/jump_arm_aapcs_elf_gas.S"

...failed gcc.compile.asm /home/lb/.conan/data/boost/1.81.0/_/_/build/ee88e4e78fdd19f4c17bdc0968692568847a4988/build-release/boost/bin.v2/libs/context/build/gcc-11/rls/abi-apcs/lnk-sttc/nm-on/thrd-mlt/vsblt-hdn/asm/jump_arm_aapcs_elf_gas.o...
gcc.compile.asm /home/lb/.conan/data/boost/1.81.0/_/_/build/ee88e4e78fdd19f4c17bdc0968692568847a4988/build-release/boost/bin.v2/libs/context/build/gcc-11/rls/abi-apcs/lnk-sttc/nm-on/thrd-mlt/vsblt-hdn/asm/ontop_arm_aapcs_elf_gas.o
ontop_arm_aapcs_elf_gas.S: Assembler messages:
ontop_arm_aapcs_elf_gas.S:57: Error: selected processor does not support `vstmia sp,{d8-d15}' in ARM mode
ontop_arm_aapcs_elf_gas.S:71: Error: selected processor does not support `vldmia sp,{d8-d15}' in ARM mode

    "arm-linux-gnueabihf-g++-11" -x assembler-with-cpp -pthread -O3 -finline-functions -Wno-inline -Wall -fvisibility=hidden -I/home/lb/.conan/data/libbacktrace/cci.20210118/_/_/package/2d7ebe5aec211724d06c7670bb80889f73c8ff36/include  -DBOOST_ALL_NO_LIB=1 -DBOOST_CONTEXT_SOURCE -DBOOST_DISABLE_ASSERTS -DBOOST_USE_NUMA -DNDEBUG -D_GLIBCXX_USE_CXX11_ABI=1 -I"." -c -o "/home/lb/.conan/data/boost/1.81.0/_/_/build/ee88e4e78fdd19f4c17bdc0968692568847a4988/build-release/boost/bin.v2/libs/context/build/gcc-11/rls/abi-apcs/lnk-sttc/nm-on/thrd-mlt/vsblt-hdn/asm/ontop_arm_aapcs_elf_gas.o" "libs/context/src/asm/ontop_arm_aapcs_elf_gas.S"

...failed gcc.compile.asm /home/lb/.conan/data/boost/1.81.0/_/_/build/ee88e4e78fdd19f4c17bdc0968692568847a4988/build-release/boost/bin.v2/libs/context/build/gcc-11/rls/abi-apcs/lnk-sttc/nm-on/thrd-mlt/vsblt-hdn/asm/ontop_arm_aapcs_elf_gas.o...

This would explain why my different cross-building attempts were successful, as I was not trying 32-bit ARM.

Looking at https://github.com/boostorg/context/issues/114 where this issue has been previously reported - it looks like the following flags would have to be added -mcpu=cortex-a5 -mfpu=neon-vfpv4 -mfloat-abi=hard so that the assembler has knowledge of the specific cpu/architecture features.

However, those flags need to match the specific CPU you are targeting. If you are able to provide details of the specific ARM SoC you are targetting, I can look this up or point you in the right direction.

@av4625, you mentioned that building natively on your ARM devices was successful. Chances are, the compiler you are using on the device is already pre-built to match the CPU you are using, and already passes the correct flags. Would you be able to run the following command locally on your ARM device to check which flags are being passed?

cat "void foo();" | gcc -x c -v -

Thanks!

Then we can take it from there :D

lukasberbuer commented 1 year ago

Big steps forward, thanks @jcar87!

In the morning, I tried to build the armv7 Conan packages via Docker and realized the same, that armv7 + boost is the problem and not the cross-build.

Small example to reproduce with an arm32v7/ubuntu:22.04 Docker image. Dockerfile:

FROM arm32v7/ubuntu:22.04

RUN apt update

RUN apt install -y build-essential cmake
RUN apt install -y python3 python3-pip

RUN pip3 install conan~=1.59

RUN conan profile new default --detect
RUN conan profile update settings.compiler.libcxx=libstdc++11 default
RUN cat ~/.conan/profiles/default

RUN conan install boost/1.81.0@ -s build_type=Debug --update --build missing

Now build the Docker image:

docker build --progress=plain .
av4625 commented 1 year ago

Thanks for spending the time on this! output.txt

I included the command you specified and also 2 more as yours errored, I created a file and compiled for c and c++. The file included:

int main(){}

From what I can see I don't think it sets -mcpu and -mfpu. But it sets -march=armv7-a+fp which maybe covers the -mfpu.

I should probably use these options when compiling my own program and conan deps:

-mfloat-abi=hard -mtls-dialect=gnu -mthumb -mlibarch=armv7-a+fp -march=armv7-a+fp

The CPU of the device is a Cortex-A7. So I could add -mcpu and -mtune.

I'm not sure what to choose for -mfpu. Maybe the answer is below for someone who knows more than me!

% cat /proc/cpuinfo
processor   : 0
model name  : ARMv7 Processor rev 5 (v7l)
BogoMIPS    : 48.00
Features    : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part    : 0xc07
CPU revision    : 5

processor   : 1
model name  : ARMv7 Processor rev 5 (v7l)
BogoMIPS    : 48.00
Features    : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part    : 0xc07
CPU revision    : 5

processor   : 2
model name  : ARMv7 Processor rev 5 (v7l)
BogoMIPS    : 48.00
Features    : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part    : 0xc07
CPU revision    : 5

processor   : 3
model name  : ARMv7 Processor rev 5 (v7l)
BogoMIPS    : 48.00
Features    : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part    : 0xc07
CPU revision    : 5

Hardware    : Allwinner sun8i Family
Revision    : 0000
% uname -a
Linux orangepizero 5.15.93-sunxi #23.02.2 SMP Fri Feb 17 23:49:46 UTC 2023 armv7l armv7l armv7l GNU/Linux
jcar87 commented 1 year ago

Hi @av4625, you're on the right track: indeed -march=armv7-a+fp encompasses the equivalent of setting some of the other flags (-mpfu for example). It would appear as much from the GCC documentation: https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html

Based on the information you have provided, I believe the following flags would work for your target CPU:

-mcpu=cortex-a7 -mfpu=neon-vfpv3 -mfloat-abi=hard

I can see that the Boost recipe will pick up ASFLAGS from the environment to pass to the assembler - so you can define it in [buildenv] along with the others.

All in all, the host profile would look like:

[settings]
os=Linux
arch=armv7
compiler=gcc
compiler.version=11
compiler.libcxx=libstdc++11
build_type=Release

[buildenv]
CHOST=arm-linux-gnueabihf
AR=arm-linux-gnueabihf-ar
AS=arm-linux-gnueabihf-as
RANLIB=arm-linux-gnueabihf-ranlib
LD=arm-linux-gnueabihf-ld
STRIP=arm-linux-gnueabihf-strip
CC=arm-linux-gnueabihf-gcc-11
CXX=arm-linux-gnueabihf-g++-11
ASFLAGS=-mcpu=cortex-a7 -mfpu=neon-vfpv3 -mfloat-abi=hard

with these changes now I'm able to cross-build boost for armv7 - hopefully this helps!

As mentioned previously, this appears to be an instance of the issue reported here: https://github.com/boostorg/context/issues/114 but also in combination with how the gcc cross-compiler provided by Ubuntu is built: https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1939379 (looks like the info from -march is not passed to the assembler).

av4625 commented 1 year ago

Thanks for this! I’ll give it a go.

I just need to figure out how to populate [buildenv] with cmake conan.

Is there a good way to know what env variables you should use? I naively thought I would use CFLAGS/CPPFLAGS as I didn’t know ASFLAGS where a thing.

Will ASFLAGS work with all 3rd party deps I get with conan or is this something I’ll need to check?

I find the conan documentation lacking (or at least I can’t find it) when it comes to all available settings/variables for profiles, I can just find examples and hopefully they contain what I need!

av4625 commented 1 year ago

I'm starting to see that you can find out the available settings/variables from the recipes. I have only used conan for simple use cases before, this is the first time I'm doing more awkward things with it and learning along the way.

@jcar87 Thank you very much for your help. I have finally got it to work.

I settled on the following compiler options:

-mfloat-abi=hard -mtls-dialect=gnu -mthumb -mlibarch=armv7-a+fp -mtune=cortex-a7 -mfpu=neon-vfpv3

I had to remove -mcpu as I. was getting:

switch '-mcpu=cortex-a7` conflicts with switch '-march=armv7-a+fp'

One slightly interesting thing is that doing cat "void foo();" | arm-linux-gnueabihf-gcc-11 -x c -v - on the linux machine shows the same output and uses the same options as doing it on the arm device itself. But I have decided to explicitly provide all the options myself now.

I will close this issue here as I believe everything is answered/fixed relating to this. I opened a question about how to add [buildenv] with cmake-conan. I will link it here incase anyone comes across this.

To get it working currently I created a profile file in my repo and added the following to my cmake (I'd rather not do it this way as most of the settings/vars in the profile duplicate the things in my cmake toolchain file):

set(CONAN_INSTALL_DATA
    SETTINGS_BUILD ${build_settings}
    PROFILE_HOST ${CMAKE_SOURCE_DIR}/toolchains/orange_pi/conan_profile)

conan_cmake_install(
    PATH_OR_REFERENCE .
    BUILD missing
    REMOTE conancenter
    ${CONAN_INSTALL_DATA})

Proof :)

$ arm-linux-gnueabihf-objdump -x /home/user/.conan/data/boost/1.81.0/_/_/package/5da9c4c21f3aeffce6fb5f7defa8feccf7677405/lib/libboost_url.a | grep architecture | head -n 1
architecture: armv7, flags 0x00000011: