Ask Your Question
0

Only available with -std=c++11 or -std=gnu++11 [closed]

asked 2021-01-24 07:27:57 -0500

serhat gravatar image

Hi everyone, I tried to use "range based for loop" and "lambdas" in my programs. Everything was fine in fact. My IDE didn't throw any error or warning at all. After "catkin_make", I see some warnings in my terminal which says:

/home/serhathp/catkin_ws/src/tcp_edu/src/trial_06.cpp:41:9: warning: lambda expressions only available with -std=c++11 or -std=gnu++11
         }
         ^

and same for "range based for loop" method. How can I handle this issue? What version of compiler do I use in my system? I typed some code in my program related to this issue:

   if (__cplusplus == 201703L) std::cout << "C++17\n";
    else if (__cplusplus == 201402L) std::cout << "C++14\n";
    else if (__cplusplus == 201103L) std::cout << "C++11\n";
    else if (__cplusplus == 199711L) std::cout << "C++98\n";
    else std::cout << "pre-standard C++\n";

As an output, I gave C++98. Maybe this would be useful information I don't know. Probably related to this issue, I can't use "range based for loop" correctly if I run my program. (I can compile my program actually) It doesn't work like it should! Any relationship? How can I change my compiler version in my system. I want it to be C++11 especially. I'm kind of confused and new at this environment. Any help?

UBUNTU 16.04 - Kinetic - Ros1. I use Visual Studio as IDE.

Thank You!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by serhat
close date 2021-01-31 12:51:31.381068

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-01-24 07:33:32 -0500

In your CMakeLists, try adding this line:

add_compile_options(-std=c++11)

edit flag offensive delete link more

Comments

I appreciate your answer. The answer was right before my eyes :D I hadn't ever realized. Thank you so much.

cmake_minimum_required(VERSION 3.0.2)
project(tcp_edu)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
serhat gravatar image serhat  ( 2021-01-24 07:53:06 -0500 )edit

No problem. Have fun!

gstavrinos gravatar image gstavrinos  ( 2021-01-24 08:13:01 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-01-24 07:27:57 -0500

Seen: 88 times

Last updated: Jan 24