c++ - 'operator/' 不是 'std::filesystem' 的成员;你的意思是'操作员~'
问题描述
我正在尝试安装 MMMTools https://mmm.humanoids.kit.edu/installation.html。我的 cmake 版本是 3.16.3。在本节之前,我完成了每一步都没有任何错误
cd ~/MMMCore
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make
该make
命令返回我以下错误。
(base) kong@kong-Standard:~/MMMCore/build$ make
[ 1%] Building CXX object CMakeFiles/MMMCore.dir/MMM/XMLTools.cpp.o
/home/kong/MMMCore/MMM/XMLTools.cpp: In function ‘void MMM::XML::makeAbsolutePath(const string&, std::string&)’:
/home/kong/MMMCore/MMM/XMLTools.cpp:650:64: error: ‘operator/’ is not a member of ‘std::filesystem’; did you mean ‘operator~’?
650 | std::filesystem::path filenameNewComplete = std::filesystem::operator/(filenameBasePath, filenameNew);
| ^~~~~~~~~
| operator~
make[2]: *** [CMakeFiles/MMMCore.dir/build.make:76: CMakeFiles/MMMCore.dir/MMM/XMLTools.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:295: CMakeFiles/MMMCore.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
但我用谷歌搜索了这个函数,发现它是 std::filesystem https://en.cppreference.com/w/cpp/filesystem/path/operator_slash的成员。什么地方出了错?
我浏览了 CMakeLists.txt 并看到了这个。
###########################################################
#### Compiler configuration ####
###########################################################
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # enable -fPIC
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /MP")
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
# cmake 3.10 does not understand c++2a, so we tell it we will handle the standard flag
set(CMAKE_CXX_STANDARD_DEFAULT)
add_definitions(-std=c++2a)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")
endif()
add_compile_options(-Werror)
我在 Ubuntu 20.04 上编译它,所以我猜它进入 elseif 部分。这是否意味着它没有使用 C++17?我是否需要编辑该行set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")
以使其使用 C++17?
该指南表明它适用于 18.04,但由于问题出在 C++17,我认为问题不在于使用 20.04?
解决方案
由于LWG 3065,操作员现在被隐藏,不应直接调用。
std::filesystem::path filenameNewComplete = std::filesystem::operator/(filenameBasePath, filenameNew);
应该只是:
std::filesystem::path filenameNewComplete = filenameBasePath / filenameNew;
我猜该代码仅针对旧实现进行了测试(看起来这是在 gcc/libstdc++ 9 中实现的)而不是您正在使用的实现,但我不知道为什么它最初以如此复杂的方式编写.
推荐阅读
- c# - Azure RelayManagementClient 的 ManagedIdentityCredential
- javascript - 确定是否检查了自定义无线电组件
- laravel - Laravel 日期验证不适用于 before_or_equal 或 after_or_equal
- c++ - 如何编写nodejs ffi napi库函数以从哪个双数组调用.dll?
- python - bigquery 的数据框结果为空
- r - R, tbl_summary 使用 gtsummary 编织成 PDF
- c++ - 对不在参数包中的类型列表的每个元素执行一个函数?
- linux - Windows Server 2016 上的 docker 容器内的 Redis
- apache-kafka - Kafka Stream:线程之间的重新平衡如何工作?
- css - 角度样式模板