简体   繁体   English

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

[英]C++ Build Failed on Xcode OSX with multiple errors File IO … is unavailable: introduced in macOS 10.15

I am getting the following error whenever I try to build my code on Xcode on my Mac.每当我尝试在 Mac 上的 Xcode 上构建代码时,都会出现以下错误。

My current system:我目前的系统:
macOS: version 10.15.1 (19B88) macOS:版本 10.15.1 (19B88)
Xcode: Version 11.2.1 (11B500) Xcode:版本 11.2.1 (11B500)

my error:我的错误:

'path' is unavailable: introduced in macOS 10.15 'path' 不可用:在 macOS 10.15 中引入
'current_path' is unavailable: introduced in macOS 10.15 'current_path' 不可用:在 macOS 10.15 中引入
'operator/' is unavailable: introduced in macOS 10.15 'operator/' 不可用:在 macOS 10.15 中引入
'path' is unavailable: introduced in macOS 10.15 'path' 不可用:在 macOS 10.15 中引入
'path' is unavailable: introduced in 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;

After running g++ on terminal I get在终端上运行g++后,我得到

clang: error: no input files clang:错误:没有输入文件

And after running g++ --version I get在运行g++ --version我得到

Configured with: --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) Target: x86_64-apple-darwin19.0.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin配置: --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 线程 Z20F35E630DAF44DBFA4C3F68F5399D8C3Xcode.Installed/DAF44DBFA4C3F68F5399D8CContent/开发者/工具链/XcodeDefault.xctoolchain/usr/bin

Using SDK 10.15, Xcode 11 and and enabling C++17 compiler solved this issue.使用 SDK 10.15、Xcode 11 并启用 C++17 编译器解决了这个问题。

To enable C++17, followi this link: Enable C++17 on Xcode, macOS要启用 C++17,请点击此链接: 在 Xcode 上启用 C++17,macOS

On your Xcode, from General setting, select 10.15 SDK as Deployment Target and you are good to go for. On your Xcode, from General setting, select 10.15 SDK as Deployment Target and you are good to go for.

Add添加

CONFIG += c++17

and

macx: {
    QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.15
}

to your.pro file.到 your.pro 文件。 That should set -std=gnu++1z -mmacosx-version-min=10.15 flags to compiler.那应该将-std=gnu++1z -mmacosx-version-min=10.15标志设置为编译器。 Also I used Apple Clang compiler both for C++ and C (may be set in Preferences -> Kits ).我还为 C++ 和 C 使用了 Apple Clang 编译器(可以在Preferences -> Kits中设置)。 Not sure if it is critical, but GCC did not work definitely.不确定它是否很关键,但 GCC 肯定没有工作。

Possible solutions to consider需要考虑的可能解决方案

Using experimental support使用实验支持

You might want to checkout the llvm docs on libc++ .您可能想 查看 libc++ 上的 llvm 文档 If you're using xcode 11.2 out of the box, you probably have llvm 8.0.如果您使用的是开箱即用的 xcode 11.2,那么您可能拥有 llvm 8.0。

Using <filesystem>使用 <文件系统>

Prior to LLVM 9.0, libc++ provides the implementation of the filesystem library in a separate static library.在 LLVM 9.0 之前,libc++ 在单独的 static 库中提供文件系统库的实现。 Users of <filesystem> and <experimental/filesystem> are required to link -lc++fs. <filesystem> 和 <experimental/filesystem> 的用户需要链接 -lc++fs。 Prior to libc++ 7.0, users of <experimental/filesystem> were required to link libc++experimental.在 libc++ 7.0 之前,<experimental/filesystem> 的用户需要链接 libc++experimental。

Starting with LLVM 9.0, support for <filesystem> is provided in the main library and nothing special is required to use <filesystem>.从 LLVM 9.0 开始,主库中提供了对 <filesystem> 的支持,使用 <filesystem> 不需要任何特殊要求。

So you'll probably need the include mentioned and the link flag.所以你可能需要提到的包含和链接标志。

Updating 9.0 or later更新 9.0 或更高版本

As the docs also eluded, you can also update to a newer version and then try to configure Xcode to use the updated version .由于文档也没有提及,您还可以更新到较新的版本,然后尝试配置 Xcode 以使用更新的版本

I don't have a Mac setup right now, so I can't walk through all of this to confirm.我现在没有 Mac 设置,所以我无法通过所有这些来确认。 But hopefully you'll get some ideas that will move you along.但希望你能得到一些能让你前进的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM