LeFish
LeFish

Reputation: 1

How to use std::filesystem library when compiling ROS2 package with colcon?

I am trying to compile my first ROS2 package using the std::filesystem library with colon build, but I am getting the following compile error:

function "std::filesystem::__cxx11::path::filename" is not a type name

This is part of the CMake of my package:

...
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()
...

As you can see above, I tried to force the compiler to use C++17. I am wondering where the ...__cxx11... statement comes from?

I also tried to use std::experimental::filesystem::path::filename without success.

Upvotes: 0

Views: 81

Answers (1)

Oswaldo Hernandez
Oswaldo Hernandez

Reputation: 1

You should not use the __cxx11.

Your header or cpp file must look like this.

#include <filesystem>

std::filesystem::path file_path = "foo.txt";

Please provide how are you using the filesystem lib

Upvotes: -1

Related Questions