Change C++ version in Cmake/linux

I am trying to change my project to building using C++14. It works on Windows and Mac by specifying the C++ standard. However, changing the C++ standard in the CMakeLists.txt doesn’t seem to do anything.

I tried changing “-std=c+=11” in the CMAKE_CXX_FLAGS. I also tried

set(CMAKE_CXX_STANDARD 14) set(CMAKE_STANDARD_REQIURED ON)

and

set(CMAKE_REQUIRED_FLAGS -std=c++14)

and

add_compile_options(-std=c++14)

In all cases, I get the same error message: “class std::map<std::__cxx11::basic_string, GameObject*> ha no member named insert_or_assign”, which clearly suggests it is building with C++11 instead.

How do I fix this?

This has worked for me:

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

I use these as like line 4+ in my file

I have not tried this in 3.17 or 3.17.1. What version of cocos2d-x are you using?

@slackmoehrle

So, I found out that map::insert_or_assign is a C++17 feature, but I have been using it in MSVC (Windows) C++14. I presume it was showing cxx11 map because C++14 didn’t make any changes to std::map. I ended up using CMAKE_CXX_STANDARD, except with 17.

1 Like
  1. Did you release Android, iOS games with C++14 enabled?
  2. Is it supported to compile/release with C++14?
  3. I think that current cocos2dx default is C++11. If everything works with C++14 maybe it is worth to switch to C++14 in CI (Travis, appveyor) and write modern code? We have 2019 :wink: