I am getting the following error whenever I try to build my code on Xcode on my Mac.
My current system:
macOS: version 10.15.1 (19B88)
Xcode: Version 11.2.1 (11B500)
my error:
'path' is unavailable: introduced in macOS 10.15
'current_path' is unavailable: introduced in macOS 10.15
'operator/' is unavailable: introduced in macOS 10.15
'path' is unavailable: introduced in macOS 10.15
'path' is unavailable: introduced in 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
clang: error: no input files
And after running g++ --version
I get
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
Using SDK 10.15, Xcode 11 and and enabling C++17 compiler solved this issue.
To enable C++17, followi this link: Enable C++17 on Xcode, macOS
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. That should set -std=gnu++1z -mmacosx-version-min=10.15
flags to compiler. Also I used Apple Clang compiler both for C++ and C (may be set in Preferences -> Kits ). Not sure if it is critical, but GCC did not work definitely.
Possible solutions to consider
You might want to checkout the llvm docs on libc++ . If you're using xcode 11.2 out of the box, you probably have llvm 8.0.
Using <filesystem>
Prior to LLVM 9.0, libc++ provides the implementation of the filesystem library in a separate static library. Users of <filesystem> and <experimental/filesystem> are required to link -lc++fs. Prior to libc++ 7.0, users of <experimental/filesystem> were required to link libc++experimental.
Starting with LLVM 9.0, support for <filesystem> is provided in the main library and nothing special is required to use <filesystem>.
So you'll probably need the include mentioned and the link flag.
As the docs also eluded, you can also update to a newer version and then try to configure Xcode to use the updated version .
I don't have a Mac setup right now, so I can't walk through all of this to confirm. But hopefully you'll get some ideas that will move you along.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.