androidc++android-ndkcocos2d-x

Android NDK - no type named 'function' in namespace 'std'


I keep getting the following error in the Android NDK when building with Cocos-2dx and Clang

jni/../../Classes/Facebook/FacebookConstants.h:44:14: error: no type named 'function' in namespace 'std'
typedef std::function<void()> FacebookLoginCallback;

TApplication.mk

NDK_TOOLCHAIN_VERSION := clang
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -DCOCOS2D_DEBUG=1

Android.mk

LOCAL_CFLAGS :=-D__GXX_EXPERIMENTAL_CXX0X__
LOCAL_CPPFLAGS  := -std=c++11
LOCAL_CFLAGS += -std=gnu++11
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := game_shared

LOCAL_MODULE_FILENAME := libgame

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../Classes/AppDelegate.cpp \
                   ../../Classes/Facebook/Request.cpp \
                   ../../Classes/FriendListCell.cpp \
                   ../../Classes/Game.cpp \
                   ../../Classes/GameListCell.cpp \
                   ../../Classes/GameListHeaderCell.cpp \
                   ../../Classes/GameScene.cpp \
                   ../../Classes/LoginScene.cpp \
                   ../../Classes/MenuScene.cpp \
                   ../../Classes/NewGameScene.cpp \
                   ../../Classes/Parse/curl/docs/examples/asiohiper.cpp \
                   ../../Classes/Parse/curl/docs/examples/htmltitle.cpp \
                   ../../Classes/Parse/HTTP.cpp \
                   ../../Classes/Parse/lib_json/json_reader.cpp \
                   ../../Classes/Parse/lib_json/json_value.cpp \
                   ../../Classes/Parse/lib_json/json_writer.cpp \
                   ../../Classes/Parse/ParseHTTP.cpp \

LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../Classes \
                      $(LOCAL_PATH)/../../Classes/Parse \
                      $(LOCAL_PATH)/../../Classes/Parse/json \
                      $(LOCAL_PATH)/../../Classes/Parse/lib_json \
                      $(LOCAL_PATH)/../../Classes/Facebook \

LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static

include $(BUILD_SHARED_LIBRARY)

$(call import-module,CocosDenshion/android) \
$(call import-module,cocos2dx) \
$(call import-module,extensions)

Solution

  • I think You don't have a linker error. You have a compiler error. The problem is, you dont have mention support of C++11 in your application. You have to use the one that comes with Clang by specifying the -std=c++11 compiler flag (APP_CPPFLAGS) in Application.mk file which is in your jni folder. i.e.

    APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -DCOCOS2D_DEBUG=1 -std=c++11