我正在尝试在MacOS上构建Boost库作为dylib。我需要为Intel架构和即将到来的Apple Silicon(arm64)架构构建它。
我下载了boost并运行了以下命令:
./bootstrap.sh
./b2 -address-model=64 architecture=combined -a
lipo -archs
始终显示生成的dylibs体系结构为x86_64
。
我有Xcode12测试版和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*/
^
7条答案
按热度按时间4smxwvx51#
下面的代码在使用Xcode 12.2的Big Sur上运行。在 Catalina 10.15.7(19H15)上,我得到了与OP相同的错误消息。
lh80um4z2#
我在Monterey使用M1(XCode 13.1),但没有得到任何其他答案,但我结合了Navan和Petr中的内容沿着其他一些位,使libboost_coroutine在x86_64上工作。我得到了以下脚本,它构建了所有boost库(为什么不呢,在M1上不需要很长时间):
这个脚本打印出
universal
目录下每个dylib的lipo信息,所以你可以很快看到每个dylib都包含了x86_64和arm64。我得到了下面的结果,也许它对你查看你的输出是否匹配很有用:tjrkku2a3#
在这里花了相当多的时间后:
https://github.com/bfgroup/b2/issues/105
我可以在arm 64上编译boost,命令行是:
./b2体系结构=arm地址-型号=64 asmflags=--目标= arm 64-苹果-达尔文21.2.0 cflags=--目标= arm 64-苹果-达尔文21.2.0 cxxflags=--目标= arm 64-苹果-达尔文21.2.0链接标志=--目标= arm 64-苹果-达尔文21.2.0-s无LZMA=1 -s无ZSTD=1 abi=aapcs
LZMA和ZSTD标志在那里,因为我的机器上没有这些库的通用二进制文件。
gojuced74#
我遇到了同样的问题,并遇到了这个answer,它是为i386和x86_64创建通用二进制文件。
要总结答案,您需要运行
./b2
两次(使用不同的工具集,因为clang总是为x86_64构建,即使您传递了适当的CXXFlags这是我用来首先单独生成所需库,然后使用
lipo
组合它们的脚本sulc1iza5#
你不需要使用lipo,你可以将
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
传递给cxxflags,它将构建一个开箱即用的通用库。lsmepo6l6#
我按照Navan Chauhan的答案,这似乎是在macOS 10.15.7和Xcode 12.3上进行的方式。
我唯一的问题是构建系统添加了额外的
-arch armv4t
clang选项(或类似的东西),这会导致构建失败。使用architecture=combine
无法工作,因为它只能管理Intel和PowerPC。对我来说有效的是:bootstrap.sh --with-toolset=clang-darwin
和cxxflags
、cflags
和linkflags
设置为-arch x86_64 -arch arm64
以及其他选项。b2 toolset=clang-darwin target-os=darwin architecture=x86 stage
和cxxflags
、cflags
和linkflags
仅设置为-arch x86_64
(以及其他选项)。b2 toolset=clang-darwin target-os=darwin architecture=arm abi=aapcs stage
和cxxflags
、cflags
和linkflags
仅设置为-arch arm64
(以及其他选项)。1.将库与
lipo
合并...我不得不将ABI也设置为 * 自动猜测-某事 * 无法识别Apple Silicon目标,因此一些汇编内容未编译-因此在构建过程中稍后会出现 * 缺失符号 *。最后,
armv4t
问题通过clang-darwin
工具集解决。目前唯一需要注意的是,两个构建版本都进入了相同的体系结构/配置目录,这可以通过自定义
user-config.jam
或在每个stage
之后立即调用install
来解决,这就是我所做的。作品:
k5ifujac7#
适用于带有M1 building boost 1.81.0的macOS
同时安装支持这两种体系结构的库