jni/../../Classes/AppDelegate.cpp:29: error: undefined reference to 'StartLayer。而且没生成libgame.so文件

分类: cocos2d-x环境搭建常见问题   304人阅读  评论(0)  收藏  举报

<1>报错。

G:/AndroidCocos2dxFile/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/game_shared/__/__/Classes/AppDelegate.o: in function AppDelegate::applicationDidFinishLaunching():jni/../../Classes/AppDelegate.cpp:29: error: undefined reference to 'StartLayer::scene()'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libgame.so] Error 1

<2>解决方案。

这个问题困扰了我快一天,因为以前运行别人的工程是没有问题的,还以为没有加上main.h和main.cpp导致的。

解决问题的方法就是,在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 := game_shared

LOCAL_MODULE_FILENAME := libgame

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../Classes/AppDelegate.cpp \
                   ../../Classes/HelloWorldScene.cpp \
                   ../../Classes/StartLayer.cpp \
                   ../../Classes/BasicLayer.cpp
                   
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)

搞定!!!   

 

然而最佳解决方案是用下面的Android.mk文件,什么都不用加,就OK了,不管里面有.cpp文件多少编译了


[plain]  view plain copy
  1. LOCAL_PATH := $(call my-dir)  
  2.    
  3. include $(CLEAR_VARS)  
  4.    
  5. LOCAL_MODULE := game_shared  
  6.    
  7. LOCAL_MODULE_FILENAME := libgame  
  8.    
  9. FILE_LIST := hellocpp/main.cpp   
  10.   
  11. FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp)  
  12.    
  13. LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)  
  14.                       
  15. LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes                     
  16.   
  17. LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static  
  18.                
  19. include $(BUILD_SHARED_LIBRARY)  
  20.    
  21. $(call import-module,CocosDenshion/android) \  
  22.  $(call import-module,cocos2dx) \  
  23.  $(call import-module,extensions)  

你可能感兴趣的:(jni/../../Classes/AppDelegate.cpp:29: error: undefined reference to 'StartLayer。而且没生成libgame.so文件)