0

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.

4
  • Can you please share your header and source file where you use std::filesystem? This sounds like a C++ issue rather than a CMake issue. Commented May 6 at 7:36
  • 1
    Please provide enough code so others can better understand or reproduce the problem.
    – Community Bot
    Commented May 6 at 7:59
  • On wich ROS2 version and OS are you compiling?
    – Anton Kesy
    Commented May 19 at 18:54
  • It would help to diagnose if you'd share what compiler you're using. There's plenty GCCs out in the wild with incomplete C++ standards support. Commented yesterday

1 Answer 1

-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

1
  • I don't think OP has __cxx11 in their code at all. Why and how it gets there is pretty much what the question is about. To my understanding, at least.
    – Friedrich
    Commented May 6 at 20:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.