How to use c++ 11 compiler to create android build?

I am using C++ 11 functions in my code. Code works fine on IOS however it would not compile for android. What could be missing ?

Application.mk contents

APP_STL := gnustl_static

APP_CPPFLAGS := -frtti \
-fsigned-char
APP_LDFLAGS := -latomic

APP_ABI := armeabi

APP_CPPFLAGS += -std=c++0x

ifeq ($(NDK_DEBUG),1)
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
APP_OPTIM := debug
else
APP_CPPFLAGS += -DNDEBUG
APP_OPTIM := release
endif
APP_PLATFORM := android-14

Android.mk contents

LOCAL_PATH := $(call my-dir)
LOCAL_CPPFLAGS += -std=gnu++0x
include $(CLEAR_VARS)

$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos)
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos/audio/include)
$(call import-add-path, $(LOCAL_PATH))

LOCAL_MODULE := MyGame_shared

LOCAL_MODULE_FILENAME := libMyGame

LOCAL_SRC_FILES := <classes mentioned here>


LOCAL_CPPFLAGS := -DSDKBOX_ENABLED \
-DSDKBOX_ENABLED
LOCAL_LDLIBS := -landroid \
-llog \
-landroid \
-llog
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes
LOCAL_WHOLE_STATIC_LIBRARIES := PluginIAP \
sdkbox \
PluginIAP \
sdkbox \
PluginGoogleAnalytics

# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END

LOCAL_WHOLE_STATIC_LIBRARIES += PluginSdkboxPlay
LOCAL_WHOLE_STATIC_LIBRARIES += PluginAdMob
LOCAL_WHOLE_STATIC_LIBRARIES += sdkbox

LOCAL_STATIC_LIBRARIES := cocos2dx_static

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)

$(call import-module,.)
$(call import-module, ./sdkbox)
$(call import-module, ./pluginadmob)
$(call import-module, ./pluginiap)
$(call import-module, ./plugingoogleanalytics)
$(call import-module, ./pluginsdkboxplay)

# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END

I am compile the build using command line

cocos compile -p android --android-studio

I am using ndk r16b to build this

I get the error

'get_time' is not member of 'std'

Please help.

Thanks.

Look at the latest Application.mk file. Your APP_CPPFLAGS entry should be changed:

It’s the -std=c++11 which sets the compile level.

PS: I changed it to c++14 and it’s still compiling without any errors.

1 Like

As @mars3142 said, You are literally setting the std to -std=c++0x not -std=c++11.

Change that and you should be good to go

APP_STL := gnustl_static

APP_CPPFLAGS := -frtti \
-fsigned-char
APP_LDFLAGS := -latomic

APP_ABI := armeabi

APP_CPPFLAGS += -std=c++11

ifeq ($(NDK_DEBUG),1)
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
APP_OPTIM := debug
else
APP_CPPFLAGS += -DNDEBUG
APP_OPTIM := release
endif
APP_PLATFORM := android-14

Also out of curiosity, which version of cocos2d-x are you using? This config seems pretty old

2 Likes

Hi,

modifying the lines

APP_STL := c++_static

APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-char -Wno-extern-c-compat

fixed it for me. Only changing c++ox to c++11 does not work.

@mozartalouis The project was creating in 3.14 version. However recently it was upgraded to 3.16.

1 Like