C++ Build 在 Xcode OSX 上失败并出现多个错误文件 IO ... 不可用:在 macOS 10.15 中引入

I. *_*nov 5 c++ macos file-io xcode

每当我尝试在 Mac 上的 Xcode 上构建代码时,都会收到以下错误。

我当前的系统:
macOS:版本 10.15.1 (19B88)
Xcode:版本 11.2.1 (11B500)

我的错误:

'path'不可用:macOS 10.15中引入
'current_path'不可用:macOS 10.15中引入
'operator/'不可用:macOS 10.15中引入
'path'不可用:macOS 10.15中引入
'path'不可用:macOS中引入10.15

主程序

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <filesystem>

using namespace std;

int main(int argc, char* argv[])
{
    cout << "being exectued from:" << endl;
    cout << argv[0] << endl;

    std::__fs::filesystem::path cwd = std::__fs::filesystem::current_path() / "filename.txt"; // C++17
    cout << "but the input.txt and output.txt files should be be in the following directory:" << endl;
    cout << cwd.string() << endl << endl;
Run Code Online (Sandbox Code Playgroud)

g++终端上运行后,我得到

铛:错误:没有输入文件

跑步后g++ --version我得到

配置为:--prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 11.0.0 (clang-1100.0.33.12) 目标:x86_64-apple-darwin19.0.0 线程模型:posix InstalledDir:/Applications/Xcode.app/Contents/开发人员/工具链/XcodeDefault.xctoolchain/usr/bin

iOS*_*iOS 6

添加

CONFIG += c++17
Run Code Online (Sandbox Code Playgroud)

macx: {
    QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.15
}
Run Code Online (Sandbox Code Playgroud)

到您的 .pro 文件。这应该-std=gnu++1z -mmacosx-version-min=10.15为编译器设置标志。我还使用 Apple Clang 编译器来编译 C++ 和 C(可以在Preferences -> Kits中设置)。不确定它是否重要,但 GCC 并没有绝对工作。


I. *_*nov 3

使用 SDK 10.15、Xcode 11 和启用 C++17 编译器解决了这个问题。

要启用 C++17,请点击此链接:在 Xcode、macOS 上启用 C++17

在 Xcode 上,从常规设置中选择10.15 SDK 作为部署目标,然后就可以选择 .

  • 不错,但这是苹果的肮脏营销伎俩。它是 C++17 标准,无论使用什么主机操作系统版本,都可以使用 Xcode 分发正确的 C++ 库。而且 CLang 不仅可以在 Xcode 中使用……那么 CMake/Make 又如何呢?- 没有什么... (3认同)