I need to use C++ 17's filesystem header for my project. As far as I know, Apple finally made it available with Xcode 11 and with macOS Catalina. I'm on the latest (beta 3) Xcode 11 and I use macOS Catalina public beta 2, so in theory it should work. But for some reason it's not, and Xcode gives errors like:
'~path' is unavailable: introduced in macOS 10.15
If I set the C++ standard library in Build Setting to libstdc++ from libc++ these error emssages gone and I got a warning:
include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead
and a ton of errors with missing iostream and cstddef in various files. What could I do to make filesystem work?
Edit: a minimal code example
#include <filesystem>
#include <iostream>
#include <string>
bool isPathDir(std::string pathString);
int main(int argc, char *argv[])
{
std::string pathString = "../test.jpg";
if (isPathDir(pathString)) {
std::cout << "This is a directory!" << std::endl;
} else {
std::cout << "This is not a directory" << std::endl;
}
}
bool isPathDir(std::string pathString)
{
std::filesystem::path path(pathString);
return std::filesystem::is_directory(path);
}
Xcode 14. This version of Xcode: Includes SDKs for iOS 16, iPadOS 16, macOS 12.3, tvOS 16, and watchOS 9. Supports on-device debugging in iOS 11 or later, tvOS 11 or later, and watchOS 4 or later.
Xcode 11 supports on-device debugging for iOS 8 and later, tvOS 9 and later, and watchOS 2 and later. Xcode 11 requires a Mac running macOS Mojave 10.14. 4 or later.
The macOS 10.15 SDK provides support for developing apps for Macs running macOS Catalina 10.15. The SDK comes bundled with Xcode 11 available from the Mac App Store.
Promoting my comment into an answer:
Do you happen to have a back-deployment target older than macOS 10.15 specified? This would appear on your command-line as something like
-mmacosx-version-min=<value>
.@LouisDionne Oh yes, that was the problem! As soon as I set the deployment target to 10.15 the code build perfectly! I've never heard of deployment targets before, thank you very much!
Just to explain what's going on here, the issue is that support for <filesystem>
was only introduced in Mac OS 10.15. When you use -mmacosx-version-min=XYZ
, you tell the compiler that your program should be able to run on versions of Mac OS all the way until version XYZ
. If you use a version older than 10.15, we nicely tell you at compile-time that you can't use <filesystem>
, because that would be a runtime error (likely symbol missing from libc++.dylib
) if you tried running the program on a version of Mac OS older than 10.15.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With