Android NDK - 命名空间'std'中没有名为'function'的类型

时间:2013-10-10 09:58:45

标签: android c++ android-ndk cocos2d-x

使用Cocos-2dx和Clang进行构建时,我在Android NDK中出现以下错误

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)

3 个答案:

答案 0 :(得分:2)

我认为您没有链接器错误。您有编译器错误。问题是,你没有在你的应用程序中提到C ++ 11的支持。您必须使用Clang附带的那个,方法是在-std=c++11文件夹中的APP_CPPFLAGS文件中指定Application.mk编译器标志(jni)。即。

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

答案 1 :(得分:0)

不要忘记将其包含在标题

#include <functional>

在我的项目cocos2d-x v3.0.0中,Android版本需要这样做,但iOS版本不需要。我想它已包含在别处。

答案 2 :(得分:0)

我遇到了同样的问题,并通过以下方式解决了它:

Android.mk 文件中,添加

LOCAL_CPP_EXTENSION += .h