Problems with NDK not supporting c++ 14

Hello there again! Three days i’ve been trying to make my win32 project work, finally got it. Now i have a problem with the android project. I guess the compiler doesn’t recognize c++ 14? How to make him recognize it? Also adding the problem file.
GameScene.cpp (3.3 KB)

Provide the entire project. Zip it all up, without the cocos folder/build folders (meaning just the source code and resources), put it in your post or provide a download link to it, and state what version of the game engine you’re using.

Just so you know, you can build with C++14/C++17 easily, but it just requires some additions to your CMakeLists.txt.

It’s really hard to tell what it is you did or didn’t do without more information.

Which cocos2d version and NDK version do you use?

You are passing -std=gnu++11 on the command line. That looks like something configured in the Cocos2d-x cmake configuration (see cmake/Modules/CocosConfigDefine.cmake line 72).

Found a temporary solution, declared make_unique by my own, this problem occured to someone before, still quite interested in why the compiler is throwing errors. You need the android.proj zip?

The latest. Cloned from github. And Android NDK r20

So i should change this:
set(CMAKE_CXX_STANDARD 11)
To:
CMAKE_CXX_STANDARD 14
Or even better 17?

Yes. How are you telling the compiler what C++ standard you want at the moment?

What do you mean? Once again, zip up the entire contents of the folder, minus the cocos2d and the cmake generated build folder you’re using for Win32 builds. So, literally everything in that folder except the engine folder and any build related folders. For example, everything highlighted in this image should be in the zip file:
image

If you also tried to build an Android version, then you need to delete the Android build folders too. They are the highlighted ones in this image, and are located in /proj.android/app/:
image

In your CMakeLists.txt, locate the line that has include(CocosBuildSet), and add any settings you want after it. For example:

include(CocosBuildSet)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)

# Make sure this and any other setting is done AFTER the "include(CocosBuildSet)", 
# since it sets the same items and overrides our settings
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Are you sure you included the relevant header file in the appropriate location?

#include <memory>

I am just typing cocos compile -p android

Yes, i’ve included the .cpp file in the project description. Do you really need all the files? Cause this occurs on compiling android only… I tried to do what you and @trojanfoe suggested, now i’ve got this. Most interesting fact - i’ve downloaded the newest CMake 2 days ago.

NDK has own cmake and it doesn’t support C++17.
Try with C++14

1 Like

You can add the following to your CMakeLists.txt to override cocos2d’s build settings:

set_target_properties(cocos2d PROPERTIES
    CXX_STANDARD 17
    CXX_STANDARD_REQUIRED YES
    CXX_EXTENSIONS NO
)

Just add it after this line:

target_link_libraries(${APP_NAME} cocos2d)

This works with NDK20.

As @dimon4eg pointed out, Android Studio comes with it’s own CMake versions (3.6.0 and 3.10.2). Doing a Google search would have directed to this page regarding how to change it:

https://developer.android.com/studio/projects/add-native-code#vanilla_cmake

It shows you how to set the Android Studio’s own CMake version to 3.10.2, since by default it is 3.6.0. It even shows you how to use your own custom CMake version, but don’t do that unless you know what you’re doing.

Well something was supplying -std=c++14 on your first command line and I don’t think it was cocos compile -p android

As the default -std=gnu++11 was also in effect, and was supplied after the -std=c++14, it was overriding it.

@trojanfoe advice worked with my case, but i needed to put CXX_STANDARD 14 as @dimon4eg specified.

OK but that wasn’t your initial issue, which was that you were compiling using C++11, instead of C++14 or C++17, which supports std::make_unique().

Well, now i am compiling with c++14) So i guess, problem solved, thank you very much!!!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.