Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Xcode 11 beta can't use C++17's <filesystem> header?

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);
}
like image 488
Hordon Avatar asked Jul 07 '19 18:07

Hordon


People also ask

Which Xcode support iOS 11?

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.

Which is minimum system requirement of macOS for Xcode 11?

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.

Which Xcode is supported in macOS Catalina?

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.


1 Answers

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.

like image 78
Louis Dionne Avatar answered Sep 30 '22 03:09

Louis Dionne