首页 > 代码库 > jni/../../Classes/AppDelegate.cpp:102: error: undefined reference to 'TestController::TestController

jni/../../Classes/AppDelegate.cpp:102: error: undefined reference to 'TestController::TestController

<1>错误信息:

[armeabi] SharedLibrary  : libcocos2dcpp.so
E:/Android/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/cocos2dcpp_shared/__/__/Classes/AppDelegate.o: in function AppDelegate::applicationDidFinishLaunching():jni/../../Classes/AppDelegate.cpp:102: error: undefined reference to ‘TestController::TestController()‘
collect2: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libcocos2dcpp.so] Error 1

<2>解决方案

解决问题的方法就是,在Android.mk中:

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../Classes/AppDelegate.cpp \
                   ../../Classes/HelloWorldScene.cpp \

在后面加上要编译的.cpp文件文件:

 

LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := cocos2dcpp_sharedLOCAL_MODULE_FILENAME := libcocos2dcppLOCAL_SRC_FILES := hellocpp/main.cpp                    ../../Classes/AppDelegate.cpp                    ../../Classes/controller.cpp                    ../../Classes/HelloWorldScene.cpp                    ../../Classes/testBasic.cpp                    ../../Classes/VisibleRect.cpp                    ../../Classes/ActionEaseTest/ActionEaseTest.cpp                    ../../Classes/ActionTest/ActionTest.cpp                    ../../Classes/ClickAndMoveTest/ClickAndMoveTest.cpp                    ../../Classes/NodeTest/NodeTest.cpp                    ../../Classes/TransitionsTest/TransitionsTest.cpp LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../ClassesLOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_staticLOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_staticLOCAL_WHOLE_STATIC_LIBRARIES += box2d_staticLOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_staticLOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_staticinclude $(BUILD_SHARED_LIBRARY)$(call import-module,cocos2dx)$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl)$(call import-module,CocosDenshion/android)$(call import-module,extensions)$(call import-module,external/Box2D)$(call import-module,external/chipmunk)

如果cpp文件太多,加起来就会很麻烦,于是我在网上找到了一种更好的解决方案:

使用下面的Android.mk文件,什么都不用加,就OK了,不管里面有.cpp文件多少编译了

LOCAL_PATH := $(call my-dir)     include $(CLEAR_VARS)     LOCAL_MODULE := game_shared     LOCAL_MODULE_FILENAME := libgame     FILE_LIST := hellocpp/main.cpp     FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp)     LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)                        LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes                       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)  



 

jni/../../Classes/AppDelegate.cpp:102: error: undefined reference to 'TestController::TestController