Thursday, June 9, 2022
HomeGame DevelopmentCocos 2dx 4.x. Allow C++17 in Android Studio - C++

Cocos 2dx 4.x. Allow C++17 in Android Studio – C++


I’m making an attempt to be taught Cocos 2dx recreation engine. I generated a easy mission with this command:

cocos new -l cpp -p com.testgame1 -d path_to_dir testgame1

Subsequent, I attempt to construct an android mission. Every little thing is profitable. Then I wrote plenty of code that makes use of C++ commonplace 14, 17. Instance (file fundamental.cpp):

void cocos_android_app_init(JNIEnv* env) {
    LOGD("cocos_android_app_init");
    std::string vec;
    std::rework(std::start(vec), std::finish(vec), std::start(vec), [](auto& elem)
                   {
                       return elem;
                   }
    );
    appDelegate.reset(new AppDelegate());
}

Right here I utilizing auto in lambda perform (standart C++ 14).
I allow help for the usual within the typical method for Android Studio in construct.gradle:

defaultConfig {
        applicationId "com.testgame1"
        minSdkVersion PROP_MIN_SDK_VERSION
        targetSdkVersion PROP_TARGET_SDK_VERSION
        versionCode 1
        versionName "1.0"

        externalNativeBuild {
            cmake {
                targets 'MyGame'
                cppFlags "-std=c++17 -frtti -fexceptions -fsigned-char"
                arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE"
            }
        }

        ndk {
            abiFilters = []
            abiFilters.addAll(PROP_APP_ABI.cut up(':').acquire{it as String})
        }
    }

But it surely doesn’t have any impact. On a clear mission (no Cocos 2dx recreation engine) the whole lot works flawlessly.
I get an error in Android Studio:

........jnihellocppmain.cpp:42:72: error: 'auto' not allowed in lambda parameter

NDK: 21.4.7075529

Learn how to repair it?


Do that:

In your recreation mission folder, open up CMakeLists.txt, and add the next after the embrace(CocosBuildSet) assertion:

set(CMAKE_CXX_STANDARD 17)

If you wish to apply C++17 to the cocos2d engine code as properly, then including this will work:

set_target_properties(cocos2d PROPERTIES
    CXX_STANDARD 17
    CXX_STANDARD_REQUIRED YES
    CXX_EXTENSIONS NO
)



1 Like

Thanks. It additionally labored for linux.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments