gpt4 book ai didi

c++ - 为什么 Xcode 11 beta 不能使用 C++17 的 header ?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:02:34 28 4
gpt4 key购买 nike

我的项目需要使用 C++ 17 的文件系统 header 。据我所知,Apple 终于在 Xcode 11 和 macOS Catalina 中提供了它。我使用的是最新的(beta 3)Xcode 11,我使用的是 macOS Catalina public beta 2,所以理论上它应该可以工作。但出于某种原因,它不是,Xcode 会给出如下错误:

'~path' is unavailable: introduced in macOS 10.15

如果我将 Build Setting 中的 C++ 标准库从 libc++ 设置为 libstdc++,这些错误消息消失了,我收到了警告:

include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead 

以及各种文件中缺少 iostream 和 cstddef 的大量错误。我该怎么做才能使文件系统正常工作?

编辑:一个最小的代码示例

#include <filesystem>
#include <iostream>
#include <string>

bool isPathDir(std::string pathString);

int main(int argc, char *argv[])
{
std::string pathString = "../test.jpg";
if (isPathDir(pathString)) {
std::cout << "This is a directory!" << std::endl;
} else {
std::cout << "This is not a directory" << std::endl;
}
}

bool isPathDir(std::string pathString)
{
std::filesystem::path path(pathString);
return std::filesystem::is_directory(path);
}

最佳答案

将我的评论提升为答案:

Do you happen to have a back-deployment target older than macOS 10.15 specified? This would appear on your command-line as something like -mmacosx-version-min=<value>.

@LouisDionne 哦,是的,这就是问题所在!一旦我将部署目标设置为 10.15,代码就会完美构建!我以前从未听说过部署目标,非常感谢!

只是为了解释这里发生了什么,问题是对 <filesystem> 的支持仅在 Mac OS 10.15 中引入。当您使用 -mmacosx-version-min=XYZ ,您告诉编译器您的程序应该能够在 Mac OS 版本上一直运行,直到版本 XYZ .如果您使用早于 10.15 的版本,我们会在编译时很好地告诉您您不能使用 <filesystem> ,因为如果您尝试在早于 10.15 的 Mac OS 版本上运行该程序,那将是一个运行时错误(可能是 libc++.dylib 中缺少符号)。

关于c++ - 为什么 Xcode 11 beta 不能使用 C++17 的 <filesystem> header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56924853/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com