10

我正在尝试在 MacOS 上将 boost 库构建为 dylib。我需要为英特尔架构和即将推出的 Apple Silicon (arm64) 架构构建它。

我下载了 boost 并运行了以下命令:

./bootstrap.sh
./b2 -address-model=64 architecture=combined -a

lipo -archs总是显示生成的 dylibs 架构是x86_64.

我有 Xcode12 beta 和 MacOS Catalina 10.15.7,

如果我在 Xcode 中创建一个项目并archs arm64 x86_64在构建设置中进行设置,我可以构建一个示例通用库。

运行命令./b2 cxxflags="-arch arm64 -arch x86_64"失败并出现以下错误:

    "clang++" -x c++ -fvisibility-inlines-hidden -m64 -O3 -Wall -fvisibility=hidden -Wno-inline -arch arm64 -arch x86_64 -ftemplate-depth-255 -fvisibility=hidden -fvisibility-inlines-hidden -DBOOST_ALL_NO_LIB=1 -DNDEBUG -I"." -c -o "bin.v2/libs/serialization/build/clang-darwin-12.0/release/link-static/threading-multi/visibility-hidden/polymorphic_xml_iarchive.o" "libs/serialization/src/polymorphic_xml_iarchive.cpp"

...failed clang-darwin.compile.c++ bin.v2/libs/serialization/build/clang-darwin-12.0/release/link-static/threading-multi/visibility-hidden/polymorphic_xml_iarchive.o...
clang-darwin.compile.c++ bin.v2/libs/serialization/build/clang-darwin-12.0/release/link-static/threading-multi/visibility-hidden/polymorphic_xml_oarchive.o
In file included from libs/serialization/src/polymorphic_xml_oarchive.cpp:16:
In file included from ./boost/serialization/config.hpp:18:
In file included from ./boost/config.hpp:57:
In file included from ./boost/config/platform/macos.hpp:28:
In file included from ./boost/config/detail/posix_features.hpp:18:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/unistd.h:71:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/_types.h:27:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:32:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/cdefs.h:807:2: error: Unsupported architecture
#error Unsupported architecture
 ^
In file included from libs/serialization/src/polymorphic_xml_oarchive.cpp:16:
In file included from ./boost/serialization/config.hpp:18:
In file included from ./boost/config.hpp:57:
In file included from ./boost/config/platform/macos.hpp:28:
In file included from ./boost/config/detail/posix_features.hpp:18:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/unistd.h:71:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/_types.h:27:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:33:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/machine/_types.h:34:2: error: architecture not supported
#error architecture not supported
 ^
In file included from libs/serialization/src/polymorphic_xml_oarchive.cpp:16:
In file included from ./boost/serialization/config.hpp:18:
In file included from ./boost/config.hpp:57:
In file included from ./boost/config/platform/macos.hpp:28:
In file included from ./boost/config/detail/posix_features.hpp:18:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/unistd.h:71:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/_types.h:27:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:55:9: error: unknown type name '__int64_t'
typedef __int64_t       __darwin_blkcnt_t;      /* total blocks */
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:56:9: error: unknown type name '__int32_t'; did you mean '__int128_t'?
typedef __int32_t       __darwin_blksize_t;     /* preferred block size */
        ^
note: '__int128_t' declared here
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:57:9: error: unknown type name '__int32_t'; did you mean '__int128_t'?
typedef __int32_t       __darwin_dev_t;         /* dev_t */
        ^
note: '__int128_t' declared here
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:60:9: error: unknown type name '__uint32_t'; did you mean '__uint128_t'?
typedef __uint32_t      __darwin_gid_t;         /* [???] process and group IDs */
        ^
note: '__uint128_t' declared here
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:61:9: error: unknown type name '__uint32_t'; did you mean '__uint128_t'?
typedef __uint32_t      __darwin_id_t;          /* [XSI] pid_t, uid_t, or gid_t*/
        ^
4

6 回答 6

4

以下适用于我在 Big Sur 上使用 Xcode 12.2。在 Catalina 10.15.7 (19H15) 上,我收到与 OP 相同的错误消息。

./bootstrap.sh --with-libraries=regex,date_time 
./b2 architecture=combined cxxflags="-arch x86_64 -arch arm64"
于 2020-12-07T17:59:25.237 回答
2

我在 Monterey 使用 M1(XCode 13.1)并未能获得任何其他答案,但我将NavanPetr的内容与其他一些位结合起来,让 libboost_coroutine 在 x86_64 上工作。我得到了以下脚本,它构建了所有的 boost 库(为什么不呢,在 M1 上不需要很长时间):

#!/bin/sh

rm -rf arm64 x86_64 universal stage bin.v2
rm -f b2 project-config*
./bootstrap.sh cxxflags="-arch x86_64 -arch arm64" cflags="-arch x86_64 -arch arm64" linkflags="-arch x86_64 -arch arm64"
./b2 toolset=clang-darwin target-os=darwin architecture=arm abi=aapcs cxxflags="-arch arm64" cflags="-arch arm64" linkflags="-arch arm64" -a
mkdir -p arm64 && cp stage/lib/*.dylib arm64
./b2 toolset=clang-darwin target-os=darwin architecture=x86 cxxflags="-arch x86_64" cflags="-arch x86_64" linkflags="-arch x86_64" abi=sysv binary-format=mach-o -a
mkdir x86_64 && cp stage/lib/*.dylib x86_64
mkdir universal
for dylib in arm64/*; do 
  lipo -create -arch arm64 $dylib -arch x86_64 x86_64/$(basename $dylib) -output universal/$(basename $dylib); 
done
for dylib in universal/*; do
  lipo $dylib -info;
done

该脚本打印出universal目录中每个 dylib 的 lipo 信息,因此您可以快速看到每个内部都有 x86_64 和 arm64。我得到了以下结果,也许看看你的输出是否匹配对你有用:

Architectures in the fat file: universal/libboost_atomic.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_chrono.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_container.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_context.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_contract.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_coroutine.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_date_time.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_filesystem.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_graph.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_iostreams.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_locale.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_log.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_log_setup.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_numpy27.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_prg_exec_monitor.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_program_options.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_python27.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_random.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_regex.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_serialization.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_stacktrace_addr2line.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_stacktrace_basic.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_stacktrace_noop.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_system.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_thread.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_timer.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_type_erasure.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_unit_test_framework.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_wave.dylib are: x86_64 arm64 
Architectures in the fat file: universal/libboost_wserialization.dylib are: x86_64 arm64 
于 2021-11-11T07:59:12.463 回答
1

在这里花了相当多的时间后:

https://github.com/bfgroup/b2/issues/105

我能够在 arm64 上编译 boost。命令行是:

./b2 架构=arm 地址模型=64 asmflags=--target=arm64-apple-darwin21.2.0 cflags=--target=arm64-apple-darwin21.2.0 cxxflags=--target=arm64-apple-darwin21.2.0 linkflags=--target=arm64-apple-darwin21.2.0 -s NO_LZMA=1 -s NO_ZSTD=1 abi=aapcs

LZMA 和 ZSTD 标志在那里,因为我的机器上没有这些库的通用二进制文件。

于 2021-12-16T20:53:54.570 回答
1

我遇到了同样的问题并遇到了这个答案,它是为 i386 和 x86_64 创建通用二进制文件。

总结答案,您需要运行./b2两次(使用不同的工具集,因为 clang 始终为 x86_64 构建,即使您通过了适当的 CXXFlags

这是我用来首先单独生成我需要的库然后使用组合它们的脚本lipo

#!/bin/sh

rm -rf arm64 x86_64 universal
./bootstrap.sh --with-toolset=clang --with-libraries=thread,system,filesystem,program_options,serialization 
./b2  cxxflags="-arch arm64" toolset=darwin -a
mkdir -p arm64 && cp stage/lib/*.dylib arm64
./b2 toolset=clang cxxflags="-arch arm64 -arch x86_64" -a
mkdir x86_64 && cp stage/lib/*.dylib x86_64
mkdir universal
for dylib in arm64/*; do 
  lipo -create -arch arm64 $dylib -arch x86_64 x86_64/$(basename $dylib) -output universal/$(basename $dylib); 
done
于 2020-11-13T16:38:19.057 回答
0

我遵循了Navan Chauhan的回答,这似乎是在 macOS 10.15.7 上使用 Xcode 12.3 的方式。

我唯一的问题是构建系统正在添加额外的-arch armv4tclang 选项(或类似的东西),这会使构建失败。使用它architecture=combine不能很好地工作,因为它只能管理 Intel 和 PowerPC。相反,对我有用的是:

  1. bootstrap.sh --with-toolset=clang-darwincxxflags,cflagslinkflags设置为-arch x86_64 -arch arm64plus 附加选项。
  2. x86_64 build:b2 toolset=clang-darwin target-os=darwin architecture=x86 stagecxxflags,cflagslinkflags设置为-arch x86_64only(加上其他选项)。
  3. arm64 build:b2 toolset=clang-darwin target-os=darwin architecture=arm abi=aapcs stagecxxflags,cflagslinkflags设置为-arch arm64only(加上其他选项)。
  4. 将库与……合并lipo。</li>

我也被迫设置 ABI,因为自动猜测的东西无法识别 Apple Silicon 目标,因此某些组装内容未编译 - 因此在构建过程中稍后会丢失符号。最后这个armv4t问题被clang-darwin工具集解决了。

目前唯一需要注意的是,两个构建都进入相同的架构/配置目录,可以通过自定义或在每个构建之后user-config.jam立即调用来解决,这就是我所做的。installstage

适用于:

  • 主机平台:英特尔
  • macOS 10.15.7
  • Xcode 12.3(安装了命令行工具)
  • Boost 1.75.0(已编译为通用的相关压缩和 ICU 库)
于 2021-01-04T17:13:02.930 回答
0

你不需要使用 lipo,你可以传递 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk给 cxxflags,它会构建一个开箱即用的通用库。

于 2020-11-13T17:05:45.327 回答