C++/STD - 错误:“路径”不可用:在 macOS 10.15 中引入

C++/STD - error: 'path' is unavailable: introduced in macOS 10.15

提问人:Venelin 提问时间:11/1/2023 最后编辑:Venelin 更新时间:11/16/2023 访问量:80

问:

我正在我的 MacBook M2 Max、MacOS 13.5 Ventura 上构建 QCefView

这是我的CMakeLists,.txt:

cmake_minimum_required(VERSION 3.5)

project(CEFTest VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
add_subdirectory(QCefView)

set(PROJECT_SOURCES
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(CEFTest
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET CEFTest APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(CEFTest SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(CEFTest
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_link_libraries(CEFTest PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.CEFTest)
endif()
set_target_properties(CEFTest PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS CEFTest
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(CEFTest)
endif()

在构建时,我收到此错误:

[ 95%] Building CXX object QCefView/src/CMakeFiles/QCefView.dir/details/QCefConfigPrivate.cpp.o
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:8:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfile.h:59:58: error: 'path' is unavailable: introduced in macOS 10.15
inline QString fromFilesystemPath(const std::filesystem::path &path)
                                                         ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:909:24: note: 'path' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
                       ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:8:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfile.h:64:40: error: 'native' is unavailable: introduced in macOS 10.15
    return QString::fromStdString(path.native());
                                       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:1193:22: note: 'native' has been explicitly marked unavailable here
  const string_type& native() const noexcept { return __pn_; }
                     ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:8:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfile.h:68:25: error: 'path' is unavailable: introduced in macOS 10.15
inline std::filesystem::path toFilesystemPath(const QString &path)
                        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:909:24: note: 'path' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
                       ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:8:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfile.h:70:29: error: 'path' is unavailable: introduced in macOS 10.15
    return std::filesystem::path(reinterpret_cast<const char16_t *>(path.cbegin()),
                            ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:909:24: note: 'path' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
                       ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:8:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfile.h:70:12: error: 'path<const char16_t *>' is unavailable: introduced in macOS 10.15
    return std::filesystem::path(reinterpret_cast<const char16_t *>(path.cbegin()),
           ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:953:3: note: 'path<const char16_t *>' has been explicitly marked unavailable here
  path(_InputIt __first, _InputIt __last, format = format::auto_format) {
  ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:8:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfile.h:70:12: error: 'path' is unavailable: introduced in macOS 10.15
    return std::filesystem::path(reinterpret_cast<const char16_t *>(path.cbegin()),
           ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:953:3: note: 'path' has been explicitly marked unavailable here
  path(_InputIt __first, _InputIt __last, format = format::auto_format) {
  ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:8:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfile.h:70:12: error: '~path' is unavailable: introduced in macOS 10.15
    return std::filesystem::path(reinterpret_cast<const char16_t *>(path.cbegin()),
           ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:968:3: note: '~path' has been explicitly marked unavailable here
  ~path() = default;
  ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:8:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfile.h:128:22: error: 'path' is unavailable: introduced in macOS 10.15
    std::filesystem::path filesystemFileName() const
                     ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:909:24: note: 'path' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
                       ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:8:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfile.h:190:22: error: 'path' is unavailable: introduced in macOS 10.15
    std::filesystem::path filesystemSymLinkTarget() const
                     ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:909:24: note: 'path' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
                       ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:8:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfile.h:195:29: error: 'path' is unavailable: introduced in macOS 10.15
    static std::filesystem::path filesystemSymLinkTarget(const T &fileName)
                            ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:909:24: note: 'path' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
                       ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:8:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfile.h:129:14: error: '~path' is unavailable: introduced in macOS 10.15
    { return QtPrivate::toFilesystemPath(fileName()); }
             ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:968:3: note: '~path' has been explicitly marked unavailable here
  ~path() = default;
  ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:8:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfile.h:192:16: error: '~path' is unavailable: introduced in macOS 10.15
        return QtPrivate::toFilesystemPath(symLinkTarget());
               ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:968:3: note: '~path' has been explicitly marked unavailable here
  ~path() = default;
  ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:9:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfileinfo.h:82:22: error: 'path' is unavailable: introduced in macOS 10.15
    std::filesystem::path filesystemFilePath() const
                     ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:909:24: note: 'path' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
                       ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:9:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfileinfo.h:84:22: error: 'path' is unavailable: introduced in macOS 10.15
    std::filesystem::path filesystemAbsoluteFilePath() const
                     ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:909:24: note: 'path' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
                       ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:9:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfileinfo.h:86:22: error: 'path' is unavailable: introduced in macOS 10.15
    std::filesystem::path filesystemCanonicalFilePath() const
                     ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:909:24: note: 'path' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
                       ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:9:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfileinfo.h:100:22: error: 'path' is unavailable: introduced in macOS 10.15
    std::filesystem::path filesystemPath() const { return QtPrivate::toFilesystemPath(path()); }
                     ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:909:24: note: 'path' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
                       ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:9:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfileinfo.h:101:22: error: 'path' is unavailable: introduced in macOS 10.15
    std::filesystem::path filesystemAbsolutePath() const
                     ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:909:24: note: 'path' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
                       ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:9:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfileinfo.h:103:22: error: 'path' is unavailable: introduced in macOS 10.15
    std::filesystem::path filesystemCanonicalPath() const
                     ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:909:24: note: 'path' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
                       ^
In file included from /Users/venelin/Development/CEFTest/CEFTest/QCefView/src/details/QCefConfigPrivate.cpp:5:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/QDir:1:
In file included from /Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qdir.h:9:
/Users/venelin/Qt/6.6.0/macos/lib/QtCore.framework/Headers/qfileinfo.h:134:22: error: 'path' is unavailable: introduced in macOS 10.15
    std::filesystem::path filesystemSymLinkTarget() const
                     ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/c++/v1/filesystem:909:24: note: 'path' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
                       ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [QCefView/src/CMakeFiles/QCefView.dir/details/QCefConfigPrivate.cpp.o] Error 1
make[1]: *** [QCefView/src/CMakeFiles/QCefView.dir/all] Error 2
make: *** [all] Error 2
☁  build  

知道为什么我会收到这个错误以及如何修复它吗?

已经尝试过:但它似乎什么也没改变。cmake -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 ..

C++ 文件系统 标准

评论

1赞 user4581301 11/1/2023
Mac 默认编译为 C++98,读起来比 C++17 更先进,这是获得文件系统支持所需的最低要求,但数字是标准修订版获得批准的年份。有点像你的父母使用 Windows 2000 时你使用 Windows 11 的方式。
0赞 Venelin 11/1/2023
@user4581301我怎样才能改变它,以便在最后编译?
0赞 user4581301 11/1/2023
读取此命令并将命令添加到项目的 CMakeLists.txt 文件中。如果它已经存在,或者您无法确切确定将命令放在哪里,请将 CMakeLists.txt 文件添加到问题中,我们将帮助您修复该文件。
0赞 Venelin 11/1/2023
@user4581301我添加了CMakeLists.txt谢谢!
0赞 user4581301 11/1/2023
井。。。它在那里很好,对我来说看起来还不错。你需要一个在 Mac-Fu 中拥有比我更高的腰带的人

答:

0赞 Sheen 11/16/2023 #1
  1. std::filesystem::p ath 仅在 macOS 10.15+ 中受支持
  2. 对于 Qt 6.5 <版本,Qt 不使用 std::filesystem::p ath,因此它可以支持 10.15 以下的 macOS 版本
  3. 从 6.5 开始,Qt 只支持 macOS 11+,Qt 使用 std::filesystem::p ath

但是QCefView还是需要支持macOS 10.13+,如果你想用Qt 6.5+编译QCefView,那就意味着最低部署目标应该是macOS 11.0+。

请参考:https://github.com/CefView/QCefView/issues/341