如何解决将boost编译为通用库Intel和Apple Silicon体系结构
我正在尝试在MacOS上将dylib创建为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*/
^
解决方法
以下内容适用于使用Xcode 12.2的Big Sur。在Catalina 10.15.7(19H15)上,我收到与OP相同的错误消息。
./bootstrap.sh --with-libraries=regex,date_time
./b2 architecture=combined cxxflags="-arch x86_64 -arch arm64"
,
我也遇到了同样的问题,并遇到了这个answer,它是为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
,
您不需要使用脂质,可以通过
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
到cxxflags,它将立即建立通用库。
我遵循了 documentation 的答案,这似乎是使用 Xcode 12.3 在 macOS 10.15.7 上的方法。
我唯一的问题是构建系统添加了额外的 -arch armv4t
clang 选项(或类似的东西),这导致构建失败。使用 architecture=combine
的效果不如 Navan Chauhan。对我有用的是:
-
bootstrap.sh --with-toolset=clang-darwin
和cxxflags
、cflags
和linkflags
设置为-arch x86_64 -arch arm64
以及其他选项。 - x86_64 构建:
b2 toolset=clang-darwin target-os=darwin architecture=x86 stage
和cxxflags
、cflags
和linkflags
仅设置为-arch x86_64
(以及其他选项)。 - arm64 构建:
b2 toolset=clang-darwin target-os=darwin architecture=arm abi=aapcs stage
和cxxflags
、cflags
和linkflags
仅设置为-arch arm64
(以及其他选项)。 - 将库与
lipo
... 合并
我也被迫设置 ABI,因为 automatic-guess-something 无法识别 Apple Silicon 的目标,因此某些组装内容未编译 - 因此 缺少符号 稍后在构建期间。最后,armv4t
问题由 clang-darwin
工具集解决。
目前唯一的警告是两个构建都进入相同的架构/配置目录,这可以通过自定义 user-config.jam
或在每个 {{1} 之后立即调用 install
来解决}} 这就是我所做的。
适用于:
- 主机平台:英特尔
- macOS 10.15.7
- Xcode 12.3(安装了命令行工具)
- Boost 1.75.0(依赖压缩和 ICU 库已经编译为通用)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。