Cross-compile for Apple Silicon on an x86 Mac
I am trying to build Boost 1.79.0 shared libraries on an x86-based Mac running the latest MacOS (Monterey, 12.3.1) using the latest Xcode (13.3.1, with Apple’s clang 13.1.6). Everything works great for building shared libraries that run on an x86-based Mac. My ideal would be to build a single set of universal (a.k.a. “fat”) binaries that include both x86 and ARM code, but Boost.Build does not seem to contain an option to do that. (Such options existed in the past for Intel/PowerPC combinations and then later for 64-bit/32-bit Intel combinations.) Second best is to build two sets of binaries, one for x86 and another for ARM. I tried to do this using the option architecture=x86,arm on the b2 command line, and it does in fact build two sets of binaries with the expected file names. For instance, for filesystem it builds these two: libboost_filesystem-clang-darwin13-mt-a64-1_79.dylib libboost_filesystem-clang-darwin13-mt-x64-1_79.dylib But when I use the “file” command to inspect the types of these files, they both are reported as "Mach-O 64-bit dynamically linked shared library x86_64”. Am I doing something wrong, here? Or is there a bug in Boost.Build regarding cross-compiling? Thanks, Ian
Ian Emmons via Boost
Am I doing something wrong, here? Or is there a bug in Boost.Build regarding cross-compiling?
Seeing that there is no feedback on Boost.Build, you could try to to achieve the same with build2[1]. While there is no out-of-the box support for building fat binaries, I am sure you will be able to correctly cross-compile for M1 by specifying the compiler and the desired target. Boost packages with build2 support are available here[2]. [1] https://build2.org/ [2] https://cppget.org/?packages=libboost HTH, Boris
On Fri, Apr 22, 2022 at 8:37 AM Ian Emmons via Boost
I am trying to build Boost 1.79.0 shared libraries on an x86-based Mac running the latest MacOS (Monterey, 12.3.1) using the latest Xcode (13.3.1, with Apple’s clang 13.1.6). Everything works great for building shared libraries that run on an x86-based Mac.
My ideal would be to build a single set of universal (a.k.a. “fat”) binaries that include both x86 and ARM code, but Boost.Build does not seem to contain an option to do that. (Such options existed in the past for Intel/PowerPC combinations and then later for 64-bit/32-bit Intel combinations.)
I just put back support for doing that in this change < https://github.com/bfgroup/b2/commit/0db9a736ba169e70dc29b9bf108495fee7243f8e>. So on the next B2 release you'll be able to use that.
Second best is to build two sets of binaries, one for x86 and another for ARM. I tried to do this using the option architecture=x86,arm on the b2 command line, and it does in fact build two sets of binaries with the expected file names. For instance, for filesystem it builds these two:
libboost_filesystem-clang-darwin13-mt-a64-1_79.dylib libboost_filesystem-clang-darwin13-mt-x64-1_79.dylib
But when I use the “file” command to inspect the types of these files, they both are reported as "Mach-O 64-bit dynamically linked shared library x86_64”.
Am I doing something wrong, here? Or is there a bug in Boost.Build regarding cross-compiling?
Cross compiling using the Apple clang compiler, i.e. Xcode, is challenging in the number of flags that need to get passed in. This issue is reported in the B2 project with a workaround < https://github.com/bfgroup/b2/issues/105#issuecomment-996124460>. -- -- René Ferdinand Rivera Morell -- Don't Assume Anything -- No Supone Nada -- Robot Dreams - http://robot-dreams.net
participants (3)
-
Boris Kolpackov
-
Ian Emmons
-
René Ferdinand Rivera Morell