Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将boost编译为通用库(英特尔和苹果硅体系结构)_C++_Boost_Arm64_Xcode12_Apple Silicon - Fatal编程技术网

C++ 将boost编译为通用库(英特尔和苹果硅体系结构)

C++ 将boost编译为通用库(英特尔和苹果硅体系结构),c++,boost,arm64,xcode12,apple-silicon,C++,Boost,Arm64,Xcode12,Apple Silicon,我正在尝试在MacOS上构建boost库作为动态库。我需要为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中创建一个项目并在build set

我正在尝试在MacOS上构建boost库作为动态库。我需要为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中创建一个项目并在build settings中设置
archs arm64 x86_64
,我就可以构建一个示例通用库

运行命令
/b2 cxflags=“-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*/
        ^

我也遇到了同样的问题,这是为了为i386和x86_64创建通用二进制文件

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

这是我用来首先单独生成所需库的脚本,然后使用
lipo

!/bin/sh
rm-rf arm64 x86_64通用
./bootstrap.sh--with toolset=clang--with libraries=线程、系统、文件系统、程序选项、序列化
./b2 cxxflags=“-arch arm64”工具集=达尔文-a
mkdir-p arm64&&cp stage/lib/*.dylib arm64
./b2 toolset=clang cxflags=“-arch arm64-arch x86_64”-a
mkdir x86_64&&cp stage/lib/*.dylib x86_64
mkdir通用
对于arm64/*中的动态库;do
lipo-create-arch-arm64$dylib-arch-x86\u 64 x86\u 64/$(basename$dylib)-output-universal/$(basename$dylib);
完成

您不需要使用lipo,您可以通过
-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
到cxxflags,它将构建一个现成的通用库。

以下内容适用于我在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"
我遵循的答案似乎是在macOS 10.15.7上使用Xcode 12.3的方法

我唯一的问题是构建系统添加了额外的
-arch-armv4t
clang选项(或类似的选项),导致构建失败。使用
architecture=combine
不能像这样工作。相反,对我有效的是:

  • bootstrap.sh--使用toolset=clang darwin
    cxxflags
    cflags
    linkflags
    设置为
    -arch x86_64-arch arm64
    以及其他选项
  • x86_64构建:
    b2工具集=clang darwin target os=darwin architecture=x86 stage
    cxflags
    cflags
    linkflags
    仅设置为
    -arch x86_64
    (加上其他选项)
  • arm64构建:
    b2工具集=clang darwin target os=darwin architecture=arm abi=aapcs stage
    cxflags
    cflags
    linkflags
    仅设置为
    -arch arm64
    (加上其他选项)
  • 将库与lipo合并
  • 我还被迫设置ABI,因为自动猜测某些东西无法识别苹果硅目标,因此一些汇编文件没有编译,因此在构建过程中丢失了符号。最后,
    armv4t
    问题由
    clangdarwin
    工具集解决

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

    工作内容:

    • 主机平台:英特尔
    • macOS 10.15.7
    • Xcode 12.3(已安装命令行工具)
    • Boost 1.75.0(依赖压缩和ICU库已编译为通用)

    /bootstrap.sh——库=线程、系统、文件系统、程序选项、序列化和/b2工具集=达尔文-a cxflags=“-arch-arm64-arch-x86\u 64-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk”
    不构建通用库。使用
    lipo
    检查显示体系结构为
    x86\u 64
    仅此我使用了完整的命令:
    \build\u boost.sh./bootsrap.sh with=“--除此之外--带文件系统--带测试”cxflags=“-fvisibility=hidden-fvisibility inlines hidden-std=c++17-stdlib=libc++-arch x86_64-arch arm64-mmacosx version min=10.11-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk”cflags=“-mmacosx version=10.11”链接标志=”-std=c++17-stdlib=libc++-arch x86_64-arch arm64-mmacosx version min=10.11“
    Then
    /b2-q-a-j8 architecture=combined toolset=darwin link=static runtime link=static threading=multi\cflags=“$cflags”cxflags=“$cxfflags”mflags=“$cflags”mmflags=“$cflags”linkflags=“$cflags”linkflags=“$linkflags"\--stagedir=stage variant=release$with
    使用
    lipo-archs libboost\u文件系统进行验证。x86\u 64 arm64
    请确保您使用了最新的XCode 12.2,因为12.1没有arm位。我无法用您的命令重现这一点,您构建的是哪个boost版本?我正在尝试
    1.74.0
    构建boost 1.74。0,macOS Catalina,XCode 12.2+命令行工具关键是使用
    architecture=combined
    以及
    -isysroot
    。您遇到了什么错误?您在这里构建了什么版本的Boost?@jamieguinan。在我写下这个答案后几天,版本1.75.0就发布了,但我还没有尝试构建它。构建1.75.0 w在Big Sur(英特尔)下的Xcode 12.4中,我用这种方法得到了Navan Chauhan在上面的回复中提到的问题——静态lib是通用的,但动态lib只有x86_64。