X代码OSX上的C ++构建失败,出现多个错误文件IO .......不可用:在macOS 10.15中引入

每当我尝试在Mac上的X-Code上构建代码时,都会出现以下错误。

我当前的系统:
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中引入

main.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;

请您给予帮助。我是macOS上的新手,仍然在处理问题。

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

  

c声:错误:没有输入文件

运行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版本11.0.0(clang-1100.0.33.12)   目标:x86_64-apple-darwin19.0.0   螺纹型号:posix   InstalledDir:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

timberjack 回答:X代码OSX上的C ++构建失败,出现多个错误文件IO .......不可用:在macOS 10.15中引入

使用SDK 10.15,Xcode 11并启用C ++ 17编译器可以解决此问题。

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

在您的Xcode上,从“常规”设置中选择 10.15 SDK作为部署目标,您就可以开始使用了。

,

添加

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 确实没有工作。

本文链接:https://www.f2er.com/3070188.html

大家都在问