Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[boost] linking failure on Mac M1 arm64-osx #16630

Closed
cdcseacave opened this issue Mar 9, 2021 · 26 comments
Closed

[boost] linking failure on Mac M1 arm64-osx #16630

cdcseacave opened this issue Mar 9, 2021 · 26 comments
Assignees
Labels
category:community-triplet A PR or issue related to community triplets not officially validated by the vcpkg team.

Comments

@cdcseacave
Copy link
Contributor

cdcseacave commented Mar 9, 2021

Host Environment

  • OS: MacOS arm64-osx
  • Compiler: clang 12

To Reproduce
Steps to reproduce the behavior:
./vcpkg install boost
followed by trying to link to boost in any app.

Failure logs
Many error of this type:

ld: warning: ld: warning: ignoring file /Users/cdc/vcpkg/installed/arm64-osx/lib/libboost_program_options.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64ignoring file /Users/cdc/vcpkg/installed/arm64-osx/lib/libboost_program_options.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64

ld: warning: ignoring file /Users/cdc/vcpkg/installed/arm64-osx/lib/libboost_iostreams.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /Users/cdc/vcpkg/installed/arm64-osx/lib/libboost_iostreams.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /Users/cdc/vcpkg/installed/arm64-osx/lib/libboost_system.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /Users/cdc/vcpkg/installed/arm64-osx/lib/libboost_system.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /Users/cdc/vcpkg/installed/arm64-osx/lib/libboost_regex.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /Users/cdc/vcpkg/installed/arm64-osx/lib/libboost_regex.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
@autoantwort
Copy link
Contributor

I think you have to use --triplet=arm64-osx if you want arm64 binaries.

@PhoebeHui PhoebeHui added the category:community-triplet A PR or issue related to community triplets not officially validated by the vcpkg team. label Mar 10, 2021
@cdcseacave
Copy link
Contributor Author

I don't think that helps, as I forgot to say in the above description that I set the environment variable export VCPKG_DEFAULT_TRIPLET=arm64-osx

@cdcseacave
Copy link
Contributor Author

I have just removed boost and installed it again with explicit triplet command line parameter as suggested, but nothing changed. It is reported that boost is installed for arm64, but the errors are the same as above when trying to link:

  * boost-algorithm[core]:arm64-osx -> 1.75.0
  * boost-align[core]:arm64-osx -> 1.75.0
  * boost-any[core]:arm64-osx -> 1.75.0
  * boost-array[core]:arm64-osx -> 1.75.0
  etc

and

Installing package boost-program-options[core]:arm64-osx... done
etc

@autoantwort
Copy link
Contributor

Ok can reproduce this. boost build creates x86_64 binaries even if you pass address-model=64 architecture=arm to it. An solution could be to pass cxxflags="-arch arm64" to the boost build tool.

@cdcseacave
Copy link
Contributor Author

can you explain where exactly should I add that in the vcpkg port, and how to do this efficiently for all boost ports?

@autoantwort
Copy link
Contributor

As a quickfix add "cxxflags=-arch arm64" in vcpkg/ports/boost-modular-build-helper/CMakeLists.txt:184

@cdcseacave
Copy link
Contributor Author

@autoantwort thx for trying to help, but that does not work for me, boos does not compile anymore; I guess I'll wait for the real fix in vcpkg

@autoantwort
Copy link
Contributor

Ok strange. So your new file looks like:

...
        --hash
        -q

        "cxxflags=-arch arm64"
        threading=multi
        debug-symbols=on
...

What errors you get now?

@cdcseacave
Copy link
Contributor Author

yes, here is the error file:

[1/2] cd /Users/cdc/vcpkg/buildtrees/boost-container/src/ost-1.75.0-707de84ce8.clean/build && /Users/cdc/vcpkg/installed/arm64-osx/tools/boost-build/b2 --user-config=/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/user-config.jam --stagedir=/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/stage --build-dir=/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel runtime-link=static link=static address-model=64 architecture=arm target-os=darwin toolset=clang threadapi=pthread -sZLIB_BINARY=z -sZLIB_LIBPATH="/Users/cdc/vcpkg/installed/arm64-osx/lib/libz.a" -sBZIP2_BINARY=bz2 -sBZIP2_LIBPATH="/Users/cdc/vcpkg/installed/arm64-osx/lib/libbz2.a" variant=release --layout=system --with-atomic --with-random --with-date_time --with-filesystem --with-system --with-thread --with-chrono -sZLIB_INCLUDE="/Users/cdc/vcpkg/installed/arm64-osx/include" -sBZIP2_INCLUDE="/Users/cdc/vcpkg/installed/arm64-osx/include" -sICU_PATH="ICU_PATH-NOTFOUND" -j8 -sBOOST_ROOT=/Users/cdc/vcpkg/installed/arm64-osx/tools/boost-build -sBOOST_BUILD_PATH=/Users/cdc/vcpkg/installed/arm64-osx/tools/boost-build --debug-configuration --ignore-site-config --hash -q cxxflags=-arch\ arm64 threading=multi debug-symbols=on stage
FAILED: CMakeFiles/boost 
cd /Users/cdc/vcpkg/buildtrees/boost-container/src/ost-1.75.0-707de84ce8.clean/build && /Users/cdc/vcpkg/installed/arm64-osx/tools/boost-build/b2 --user-config=/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/user-config.jam --stagedir=/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/stage --build-dir=/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel runtime-link=static link=static address-model=64 architecture=arm target-os=darwin toolset=clang threadapi=pthread -sZLIB_BINARY=z -sZLIB_LIBPATH="/Users/cdc/vcpkg/installed/arm64-osx/lib/libz.a" -sBZIP2_BINARY=bz2 -sBZIP2_LIBPATH="/Users/cdc/vcpkg/installed/arm64-osx/lib/libbz2.a" variant=release --layout=system --with-atomic --with-random --with-date_time --with-filesystem --with-system --with-thread --with-chrono -sZLIB_INCLUDE="/Users/cdc/vcpkg/installed/arm64-osx/include" -sBZIP2_INCLUDE="/Users/cdc/vcpkg/installed/arm64-osx/include" -sICU_PATH="ICU_PATH-NOTFOUND" -j8 -sBOOST_ROOT=/Users/cdc/vcpkg/installed/arm64-osx/tools/boost-build -sBOOST_BUILD_PATH=/Users/cdc/vcpkg/installed/arm64-osx/tools/boost-build --debug-configuration --ignore-site-config --hash -q cxxflags=-arch\ arm64 threading=multi debug-symbols=on stage
notice: found boost-build.jam at /Users/cdc/vcpkg/installed/arm64-osx/tools/boost-build/boost-build.jam
notice: loading B2 from /Users/cdc/vcpkg/installed/arm64-osx/tools/boost-build/src/kernel/bootstrap.jam
notice: Site configuration files will be ignored due to the
notice: --ignore-site-config command-line option.
notice: Loading explicitly specified user configuration file:
    /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/user-config.jam
notice: Searching '/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel' for user-config configuration file 'user-config.jam'.
notice: Loading user-config configuration file 'user-config.jam' from '/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel'.
notice: will use '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++' for gcc, condition <toolset>gcc-5.4.1
notice: using gcc libraries :: <toolset>gcc-5.4.1 :: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib32 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib64
notice: using gcc archiver :: <toolset>gcc-5.4.1 :: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar
notice: using gcc ranlib :: <toolset>gcc-5.4.1 :: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib
warning: toolset gcc initialization: can not find tool windres
warning: initialized from /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/user-config.jam:22
notice: using rc compiler :: <toolset>gcc-5.4.1 :: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/as
notice: [cmdline-cfg] toolset clang not previously configured; attempting to auto-configure now
notice: will use 'clang++' for clang-darwin, condition <toolset>clang-12.0
...patience...
...found 208 targets...
...updating 15 targets...
clang-darwin.compile.c++ /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/dlmalloc.o
clang-darwin.compile.c++ /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/unsynchronized_pool_resource.o
clang-darwin.compile.c++ /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/global_resource.o
clang-darwin.compile.c++ /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/synchronized_pool_resource.o
clang-darwin.compile.c++ /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/monotonic_buffer_resource.o
clang-darwin.compile.c++ /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/pool_resource.o
clang-darwin.compile.c /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/alloc_lib.o
clang-darwin.archive /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a(dlmalloc.o) cputype (16777228) does not match previous archive members cputype (16777223) (all members must match)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a(global_resource.o) cputype (16777228) does not match previous archive members cputype (16777223) (all members must match)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a(monotonic_buffer_resource.o) cputype (16777228) does not match previous archive members cputype (16777223) (all members must match)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a(pool_resource.o) cputype (16777228) does not match previous archive members cputype (16777223) (all members must match)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a(synchronized_pool_resource.o) cputype (16777228) does not match previous archive members cputype (16777223) (all members must match)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a(unsynchronized_pool_resource.o) cputype (16777228) does not match previous archive members cputype (16777223) (all members must match)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a(dlmalloc.o) cputype (16777228) does not match previous archive members cputype (16777223) (all members must match)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a(global_resource.o) cputype (16777228) does not match previous archive members cputype (16777223) (all members must match)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a(monotonic_buffer_resource.o) cputype (16777228) does not match previous archive members cputype (16777223) (all members must match)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a(pool_resource.o) cputype (16777228) does not match previous archive members cputype (16777223) (all members must match)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a(synchronized_pool_resource.o) cputype (16777228) does not match previous archive members cputype (16777223) (all members must match)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a(unsynchronized_pool_resource.o) cputype (16777228) does not match previous archive members cputype (16777223) (all members must match)

  "ar"  rc "/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a" "/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/alloc_lib.o" "/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/dlmalloc.o" "/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/global_resource.o" "/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/monotonic_buffer_resource.o" "/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/pool_resource.o" "/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/synchronized_pool_resource.o" "/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/unsynchronized_pool_resource.o"
  "ranlib" "-cs" "/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a"

...failed clang-darwin.archive /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a...
...removing /Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb/libboost_container.a
...skipped <p/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/stage/lib>libboost_container.a for lack of <p/Users/cdc/vcpkg/buildtrees/boost-container/arm64-osx-rel/boost/build/03f23656e773e2695ab2b4a783e042cb>libboost_container.a...
...failed updating 1 target...
...skipped 1 target...
...updated 13 targets...
ninja: build stopped: subcommand failed.

@autoantwort
Copy link
Contributor

Hm. My config is nearly the same (see here). The only difference is that it is using the build in zlib library.

@cdcseacave
Copy link
Contributor Author

is really no one interested in using boost on arm64?

@autoantwort
Copy link
Contributor

Seems not, because x64 just works, but I have created an issue at boost-build

@autoantwort
Copy link
Contributor

Does it work if you remove this line?

@cdcseacave
Copy link
Contributor Author

yes, I confirm that by removing that line it works on arm64

@zhaoming029
Copy link

zhaoming029 commented Apr 21, 2021

@autoantwort Hi, is it possible that we can build universal libraries for boost? Here is my command:
./b2 --prefix="/Users/zhaoma/USD-21.02/output/3prelease" --build-dir="/Users/zhaoma/USD-21.02/release/build" -j12 address-model=64 link=shared runtime-link=shared threading=multi variant=release --with-atomic --with-program_options --with-regex toolset=clang architecture=combined cxxflags="-arch x86_64 -arch arm64" install

However when I check:

lipo -archs /Users/zhaoma/USD-21.02/release/build/boost/bin.v2/libs/program_options/build/clang-darwin-12.0/release/architecture-combined/threading-multi/visibility-hidden/libboost_program_options.dylib 
**x86_64**

I am using boost 1.72.0 any suggestions? Thank you!

@autoantwort
Copy link
Contributor

yes, I confirm that by removing that line it works on arm64

This workaround (remove --hash) does not work for me anymore (latest macOS + vcpkg master). Can you confirm that @cdcseacave ?

@treellama
Copy link

Even if I remove --hash from both CMakeLists.txt and boost-modular-build.cmake, it still shows up in build.ninja. Likewise, no amount of cxxflags I add to either of those files end up being used. Is there a layer of caching somewhere I'm missing? Do I have to build the entire boost metapackage?

@treellama
Copy link

Never mind, I found they are copied to installed/arch/share/boost-build and used from there. So it's necessary to remove and reinstall boost-modular-build-helper to get the new files in place.

I can confirm, removing --hash is not sufficient to get arm64 libraries generated.

@treellama
Copy link

Building off the universal binary link above, the following modification to ports/boost-modular-build-helper/CMakeLists.txt appears to build both x64 and arm64 binaries, depending on the target.

--- a/ports/boost-modular-build-helper/CMakeLists.txt                         
+++ b/ports/boost-modular-build-helper/CMakeLists.txt                         
@@ -46,7 +46,11 @@ else()                                                     
 endif()                                                                      
                                                                              
 if(APPLE)                                                                    
-    list(APPEND B2_OPTIONS target-os=darwin toolset=clang)                   
+    if (VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")                          
+        list(APPEND B2_OPTIONS target-os=darwin toolset=darwin cxxflags=\"-arch;arm64\")                                                                  
+    else()                                                                   
+        list(APPEND B2_OPTIONS target-os=darwin toolset=clang)               
+    endif()                                                                  
 elseif(WIN32)                                                                
     list(APPEND B2_OPTIONS target-os=windows toolset=gcc)                    
 elseif(ANDROID)                                                              

@kafeg
Copy link
Contributor

kafeg commented May 31, 2021

Hey @treellama! I tried your solution and it definitelly works and boost builds for arm64, but then boost-locale starts failing with

-- Building arm64-osx-dbg
CMake Error at installed/arm64-osx/share/boost-build/boost-modular-build.cmake:122 (message):
  No libraries were produced.  This indicates a failure while building the
  boost library.
Call Stack (most recent call first):
  ports/boost-locale/portfile.cmake:23 (boost_modular_build)
  scripts/ports.cmake:139 (include)

But I'm sure this is the separate problem.

Could you please create PR with your change?

@treellama
Copy link

treellama commented May 31, 2021

I definitely did not try to build all of boost, just the modules our project needs. I can submit a PR but jamming cxxflags in is not ideal, and ordinarily would break overriding of CXXFLAGS, but according to #11132 that is already broken :D

@vejmartin
Copy link
Contributor

Possibly fixed by: #18529.

@PhoebeHui
Copy link
Contributor

@cdcseacave, could you help double confirm if this has been resolved?

@cdcseacave
Copy link
Contributor Author

yes, this is solved now, thx

@PhoebeHui
Copy link
Contributor

Thanks for your response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:community-triplet A PR or issue related to community triplets not officially validated by the vcpkg team.
Projects
None yet
Development

No branches or pull requests

7 participants