ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This isn't really anything specific to Colcon, but more a CMake "thing".

You don't set CMAKE_CXX_FLAGS to -std=c++17, but you can just set CMAKE_CXX_STANDARD to 17 directly.

I would expect the command you show to work with that one change (I like to split things across multiple lines for readability, this is still just a single command):

colcon build \
  --cmake-args \
    -DCMAKE_CXX_STANDARD=17

(make sure to remove the build directory from your workspace to avoid CMake caching things)

If it still doesn't work, that would imply something else is wrong.

PS: note that if you'd like to build only specific packages with specific cmake-args, you'd use a Colcon meta file. The command line as proposed by you will apply to all packages built by that specific Colcon invocation.

This isn't really anything specific to Colcon, but more a CMake "thing".

You don't set CMAKE_CXX_FLAGS to -std=c++17, but you can just set CMAKE_CXX_STANDARD to 17 directly.

I would expect the command you show to work with that one change (I like to split things across multiple lines for readability, this is still just a single command):

colcon build \
  --cmake-args \
    -DCMAKE_CXX_STANDARD=17

(make sure to remove the build directory from your workspace to avoid CMake caching things)

If it still doesn't work, that would imply something else is wrong.

PS: note that if you'd like to build only specific packages with specific cmake-args, you'd use a Colcon meta file. The command line as proposed by you will apply to all packages built by that specific Colcon invocation.

And as you already know, asking multiple questions in a single post is not really a good idea, so:

If this isn't the solution to the std::variant build error, can someone please point me in the direction of the solution?

this would seem to be the actual question.

With the information in your current post I can't say what is causing your problem. You could try to see what Colcon CMake is actually executing with:

colcon build \
  --event-handlers console_direct+ \
  --cmake-args \
    -DCMAKE_VERBOSE_MAKEFILE=ON

(and perhaps a --packages-up-to or --packages-select to avoid trying to build everything)

That could give you a clue as to which exact commands are being executed.

This isn't really anything specific to Colcon, but more a CMake "thing".

You don't set CMAKE_CXX_FLAGS to -std=c++17, but you can just set CMAKE_CXX_STANDARD to 17 directly.

I would expect the command you show to work with that one change (I like to split things across multiple lines for readability, this is still just a single command):

colcon build \
  --cmake-args \
    -DCMAKE_CXX_STANDARD=17

(make sure to remove the build directory from your workspace to avoid CMake caching things)

If it still doesn't work, that would imply something else is wrong.

PS: note that if you'd like to build only specific packages with specific cmake-args, you'd use a Colcon meta file. The command line as proposed by you will apply to all packages built by that specific Colcon invocation.

And as you already know, asking multiple questions in a single post is not really a good idea, so:

If this isn't the solution to the std::variant build error, can someone please point me in the direction of the solution?

this would seem to be the actual question.

With the information in your current post I can't say what is causing your problem. You could try to see what Colcon CMake is actually executing with:

colcon build \
  --event-handlers console_direct+ \
  --cmake-args \
    -DCMAKE_VERBOSE_MAKEFILE=ON

(and perhaps a --packages-up-to or --packages-select to avoid trying to build everything)

That could give you a clue as to which exact commands are being executed.

I'm surprised by this as there are a a few posts around the place suggesting that Galactic requires C++17 (see here) but I couldn't find any reference to this on the Galactic release page.

It's stated here, in REP 2000: ROS 2 Releases and Target Platforms: Galactic Geochelone (May 2021 - November 2022):

Minimum language requirements:

  • C++17

as well as on the Galactic version of the Code style and language versions page:

Standard

Galactic targets C++17.

This isn't really anything specific to Colcon, but more a CMake "thing".

You don't set CMAKE_CXX_FLAGS to -std=c++17, but you can just set CMAKE_CXX_STANDARD to 17 directly.

I would expect the command you show to work with that one change (I like to split things across multiple lines for readability, this is still just a single command):

colcon build \
  --cmake-args \
    -DCMAKE_CXX_STANDARD=17

(make sure to remove the build directory from your workspace to avoid CMake caching things)

If it still doesn't work, that would imply something else is wrong.

PS: note that if you'd like to build only specific packages with specific cmake-args, you'd use a Colcon meta file. The command line as proposed by you will apply to all packages built by that specific Colcon invocation.

And as As you already know, asking multiple questions in a single post is not really a good idea, so:

If this isn't the solution to the std::variant build error, can someone please point me in the direction of the solution?

this would seem to be the actual question.

With the information in your current post I can't say what is causing your problem. You could try to see what Colcon CMake is actually executing with:

colcon build \
  --event-handlers console_direct+ \
  --cmake-args \
    -DCMAKE_VERBOSE_MAKEFILE=ON

(and perhaps a --packages-up-to or --packages-select to avoid trying to build everything)

That could give you a clue as to which exact commands are being executed.

Having written that: overriding the specific C++ standard for a CMake project isn't really anything specific to Colcon, but more a CMake "thing".

You don't set CMAKE_CXX_FLAGS to -std=c++17, but set CMAKE_CXX_STANDARD to 17 directly.

I would expect the command you show to work with that one change (I like to split things across multiple lines for readability, this is still just a single command):

colcon build \
  --cmake-args \
    -DCMAKE_CXX_STANDARD=17

(make sure to remove the build directory from your workspace to avoid CMake caching things)

If it still doesn't work, that would imply something else is wrong.

PS: note that if you'd like to build only specific packages with specific cmake-args, you'd use a Colcon meta file. The command line as proposed by you will apply to all packages built by that specific Colcon invocation.

I'm surprised by this as there are a a few posts around the place suggesting that Galactic requires C++17 (see here) but I couldn't find any reference to this on the Galactic release page.

It's stated here, in REP 2000: ROS 2 Releases and Target Platforms: Galactic Geochelone (May 2021 - November 2022):

Minimum language requirements:

  • C++17

as well as on the Galactic version of the Code style and language versions page:

Standard

Galactic targets C++17.

As you already know, asking multiple questions in a single post is not really a good idea, so:

If this isn't the solution to the std::variant build error, can someone please point me in the direction of the solution?

this would seem to be the actual question.

With the information in your current post I can't say what is causing your problem.

rclcpp on Galactic already sets the C++ version to 17 (from here):

# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 17)
endif()

You should not need to change anything there.

To see what's happening, you could try to see what Colcon CMake is actually executing with:

colcon build \
  --event-handlers console_direct+ \
  --cmake-args \
    -DCMAKE_VERBOSE_MAKEFILE=ON

(and perhaps a --packages-up-to or --packages-select to avoid trying to build everything)

That could give you a clue as to which exact commands are being executed.

Having written that: overriding the specific C++ standard for a CMake project isn't really anything specific to Colcon, but more a CMake "thing".

You don't set CMAKE_CXX_FLAGS to -std=c++17, but set CMAKE_CXX_STANDARD to 17 directly.

I would expect the command you show to work with that one change (I like to split things across multiple lines for readability, this is still just a single command):

colcon build \
  --cmake-args \
    -DCMAKE_CXX_STANDARD=17

(make sure to remove the build directory from your workspace to avoid CMake caching things)

If it still doesn't work, that would imply something else is wrong.

PS: note that if you'd like to build only specific packages with specific cmake-args, you'd use a Colcon meta file. The command line as proposed by you will apply to all packages built by that specific Colcon invocation.

I'm surprised by this as there are a a few posts around the place suggesting that Galactic requires C++17 (see here) but I couldn't find any reference to this on the Galactic release page.

It's stated here, in REP 2000: ROS 2 Releases and Target Platforms: Galactic Geochelone (May 2021 - November 2022):

Minimum language requirements:

  • C++17

as well as on the Galactic version of the Code style and language versions page:

Standard

Galactic targets C++17.