[英]Cocos2D-X compile Linux Error: Undefined Reference
I'm new to cocos2D-X (v 3.6), I'm using Linux to compile and run my project. 我是cocos2D-X(v 3.6)的新手,正在使用Linux编译和运行我的项目。 When I try the following command line:
当我尝试以下命令行时:
cocos compile -p linux
It gives me errors: 它给了我错误:
Linking CXX executable bin/MyGame
CMakeFiles/MyGame.dir/Classes/AppDelegate.cpp.o: In function `AppDelegate::applicationDidFinishLaunching()':
/home/caisar/MyCompany/MyGame/Classes/AppDelegate.cpp:53: undefined reference to `GraphicsScene::createScene()'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/MyGame] Error 1
make[1]: *** [CMakeFiles/MyGame.dir/all] Error 2
make: *** [all] Error 2
Error running command, return code: 2
This is my GraphicsScene.h
: 这是我的
GraphicsScene.h
:
#ifndef __GRAPHICS_SCENE_H__
#define __GRAPHICS_SCENE_H__
#include "cocos2d.h"
class GraphicsScene : public cocos2d::Layer{
public:
static cocos2d::Scene* createScene();
virtual bool init();
void menuCloseCallback(cocos2d::Ref* pSender);
CREATE_FUNC(GraphicsScene);
};
#endif
And this is my GraphicsScene.cpp
: 这是我的
GraphicsScene.cpp
:
#include "GraphicsScene.h"
USING_NS_CC;
Scene* GraphicsScene::createScene(){
auto scene = Scene::create();
auto layer = GraphicsScene::create();
scene->addChild(layer);
return scene;
}
bool GraphicsScene::init(){
if(!Layer::init()){
return false;
}
auto sprite = Sprite::create("autobot.png");
sprite->setPosition(0,0);
this->addChild(sprite, 0);
return true;
}
void GraphicsScene::menuCloseCallback(Ref* pSender)
{
Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
Is there anything else I need to add? 还有什么我需要补充的吗?
I also had this problem today and solved it by editing the PROJECT_PATH/CMakeLists.txt
file. 我今天也遇到了这个问题,并通过编辑
PROJECT_PATH/CMakeLists.txt
文件解决了该问题。 You must include the *.cpp and *.h filepaths in the GAME_SRC
and GAME_HEADERS
sections. 您必须在
GAME_SRC
和GAME_HEADERS
部分中包含* .cpp和* .h文件路径。 For example, in your case it must be something like this: 例如,您的情况必须是这样的:
set(GAME_SRC
Classes/AppDelegate.cpp
Classes/HelloWorld.cpp
Classes/GraphicsScene.cpp
${PLATFORM_SPECIFIC_SRC}
)
set(GAME_HEADERS
Classes/AppDelegate.h
Classes/HelloWorld.h
Classes/GraphicsScene.h
${PLATFORM_SPECIFIC_HEADERS}
)
Hope that it works! 希望它能起作用!
I guess the linker did not find the .cpp source file for GraphicsScene::createScene(). 我猜链接器没有找到GraphicsScene :: createScene()的.cpp源文件。 And you should add GraphicsScene.cpp to Android.mk file.
并且您应该将GraphicsScene.cpp添加到Android.mk文件。 Such as i did that for my project on windows.
就像我在Windows上为我的项目所做的那样。
LOCAL_SRC_FILES := hellocpp/main.cpp \\ LOCAL_SRC_FILES:= hellocpp / main.cpp \\
../../Classes/Graphic_Image.cpp \
Hope it help. 希望对您有所帮助。 Thanks.
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.