【问题标题】:C++ Build Failed on Xcode OSX with multiple errors File IO ... is unavailable: introduced in macOS 10.15C++ Build Failed on Xcode OSX with multiple errors File IO ...不可用:在macOS 10.15中引入
【发布时间】:2020-03-15 12:04:31
【问题描述】:

每当我尝试在 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 中引入
“路径”不可用:在 macOS 10.15 中引入
'path' 不可用:在 macOS 10.15 中引入

ma​​in.cpp

#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;

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

clang:错误:没有输入文件

在运行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 苹果 clang 版本 11.0.0 (clang-1100.0.33.12) 目标:x86_64-apple-darwin19.0.0 线程模型:posix 安装目录:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

【问题讨论】:

  • 请将错误发布为文本,而不是图像。不是每个人都能看到图片。
  • 好的,改变 rn
  • 你为什么用std::__fs::filesystem而不是std::filesystem
  • 你的项目必须使用10.15 SDK;在您的项目设置中更改它。这与 正在运行的操作系统版本无关;这是关于你的目标。
  • 所以基本上我需要使用 10.15 SDK,无论我的操作系统运行什么版本。非常感谢@BradAllred 花时间帮助这个便便灵魂。现在一切都很好。再次感谢你。

标签: c++ xcode macos file-io


【解决方案1】:

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

要启用 C++17,请点击此链接:Enable C++17 on Xcode, macOS

在您的 Xcode 上,从 General 设置中,选择 10.15 SDK 作为 Deployment Target,然后就可以使用了。

【讨论】:

  • 不错,但这是来自 Apple 的肮脏营销手段。它是 C++17 标准,无论使用什么主机操作系统版本,都不会阻止使用 Xcode 分发适当的 c++ 库。此外,CLang 不仅可以从 Xcode 中使用……那么 CMake/Make 呢? - 没什么...
【解决方案2】:

添加

CONFIG += c++17

macx: {
    QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.15
}

到您的 .pro 文件。 那应该将-std=gnu++1z -mmacosx-version-min=10.15 标志设置为编译器。 我还为 C++ 和 C 使用了 Apple Clang 编译器(可以在 Preferences -> Kits 中设置)。不确定它是否很重要,但 GCC 肯定不能正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-04
    • 2014-11-20
    • 2022-12-02
    相关资源
    最近更新 更多