【发布时间】:2021-09-24 04:14:12
【问题描述】:
我正在尝试安装 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?
【问题讨论】:
-
operator/自 C++17 起是std::filesystem的成员。 makefile 指定了什么标准? -
@Chris 我已经更新了我的帖子以包含 CMakeLists.txt 中指定编译器的部分。我需要将其更改为 C++17 吗?我是 CMake 的新手。
-
拼写
std::filesystem::operator/(filenameBasePath, filenameNew)违背了operator/的目的。一个应该使用filenameBasePath/filenameNew。只是说。
标签: c++ makefile cmake std-filesystem