(Cocos2dx-v3)Android - 如何解决“cocos2d.h:没有这样的文件或目录”?

时间:2016-07-06 00:12:51

标签: android eclipse cocos2d-x cocos2d-x-3.0 cocos2d-android

在我的cocos2dx项目目录的终端中, 我输入了

[armeabi-v7a] Compile++ thumb: MyGame_shared <= main.cpp
[armeabi-v7a] Compile++ thumb: MyGame_shared <= AppDelegate.cpp
[armeabi-v7a] Compile++ thumb: MyGame_shared <= HelloWorldScene.cpp
[armeabi-v7a] Compile++ thumb: MyGame_shared <= CharacterSelectScene.cpp
[armeabi-v7a] Compile++ thumb: MyGame_shared <= LanguageManager.cpp
[armeabi-v7a] Compile++ thumb: MyGame_shared <= GameMaster.cpp
[armeabi-v7a] Compile++ thumb: MyGame_shared <= Player.cpp
[armeabi-v7a] StaticLibrary  : libextension.a
In file included from jni/../../Classes/HelloWorldScene.cpp:1:0:
jni/../../Classes/HelloWorldScene.h:4:21: fatal error: cocos2d.h: No such file or directory
 #include "cocos2d.h"
                     ^
compilation terminated.
In file included from jni/hellocpp/main.cpp:1:0:
jni/../../Classes/AppDelegate.h:4:21: fatal error: cocos2d.h: No such file or directory
 #include "cocos2d.h"
                     ^
compilation terminated.
In file included from jni/../../Classes/AppDelegate.cpp:1:0:
jni/../../Classes/AppDelegate.h:4:21: fatal error: cocos2d.h: No such file or directory
 #include "cocos2d.h"
                     ^
compilation terminated.
make: *** [obj/local/armeabi-v7a/objs-debug/MyGame_shared/__/__/Classes/HelloWorldScene.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [obj/local/armeabi-v7a/objs-debug/MyGame_shared/__/__/Classes/AppDelegate.o] Error 1
make: *** [obj/local/armeabi-v7a/objs-debug/MyGame_shared/hellocpp/main.o] Error 1
In file included from jni/../../Classes/Player.cpp:9:0:
jni/../../Classes/Player.h:12:21: fatal error: cocos2d.h: No such file or directory
 #include "cocos2d.h"
                     ^
compilation terminated.
In file included from jni/../../Classes/GameMaster.cpp:9:0:
jni/../../Classes/GameMaster.h:12:21: fatal error: cocos2d.h: No such file or directory
 #include "cocos2d.h"
                     ^
compilation terminated.
make: *** [obj/local/armeabi-v7a/objs-debug/MyGame_shared/__/__/Classes/Player.o] Error 1
make: *** [obj/local/armeabi-v7a/objs-debug/MyGame_shared/__/__/Classes/GameMaster.o] Error 1
In file included from jni/../../Classes/CharacterSelectScene.cpp:9:0:
jni/../../Classes/CharacterSelectScene.h:12:21: fatal error: cocos2d.h: No such file or directory
 #include "cocos2d.h"
                     ^
compilation terminated.
make: *** [obj/local/armeabi-v7a/objs-debug/MyGame_shared/__/__/Classes/CharacterSelectScene.o] Error 1
In file included from jni/../../Classes/LanguageManager.cpp:2:0:
jni/../../Classes/LanguageManager.h:8:21: fatal error: cocos2d.h: No such file or directory
 #include "cocos2d.h"
                     ^
compilation terminated.
make: *** [obj/local/armeabi-v7a/objs-debug/MyGame_shared/__/__/Classes/LanguageManager.o] Error 1
Error running command, return code: 2.    

来了这个错误日志。

 "add the path to the folder that contains the cocos2d.h header file"

我在链接

中发现了类似的问题

Cocos2d.h No such file or directory

但我不知道如何

{{1}}

有谁能告诉我解决这个问题的步骤?

1 个答案:

答案 0 :(得分:2)

这可能是您在cocos2d-x开始新生活后遇到的非常烦人的错误之一。有几件事需要检查。

  

从eclipse导入libcocos2dx

Ctrl + N

> Android Project from Existing Code 
    > yourDirectory\cocos2d-x-3.yourVersion\cocos2d\cocos\platform

如果这没有用,请添加,您需要为.cpp中的类和Android.mk文件提供绝对路径,我认为这是您需要的。

展开项目列表(我假设test是您的项目名称)

   > test 
     > jni
       > Android.mk

替换它:

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

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes

有了这个:

CPP_FILES := $(shell find $(LOCAL_PATH)/../../Classes -name *.cpp)
LOCAL_SRC_FILES := hellocpp/main.cpp
LOCAL_SRC_FILES += $(CPP_FILES:$(LOCAL_PATH)/%=%)
LOCAL_C_INCLUDES := $(shell find $(LOCAL_PATH)/../../Classes -type d)