Help: something is wrong when I compile the Tutorials's program to android platform

Help: something is wrong when I compile the Tutorials's program to android platform
0.0 0


I follow the instructions in the Tutorials, everything is OK in the win32 VS2008 environment. But I complie the classes in the cygwin for andorid platform, the error is following:

Scene.o: In function `GameOverScene’:
D:/android/cocos2d-1.0.0-x-0.9.0/simplegame/Classes/GameOverScene.h:22: undefine
d reference to `vtable for GameOverScene’
Scene.o: In function `GameOverScene::node()‘:
D:/android/cocos2d-1.0.0-x-0.9.0/simplegame/Classes/GameOverScene.h:25: undefine
d reference to `GameOverScene::init()’
collect2: ld returned 1 exit status
make: * [/cygdrive/d/android/cocos2d-1.0.0-x-0.9.0/simplegame/android/obj/local/armeabi/] Error 1

I check the program very carefully. I found the information in the Chapter 7 - Some Icing on the Cake.
2. The function node() is convenient for developers because of integration of new, init, and autorelease, etc… But there is no keyword like self(objc) in c++, so CCLayer::node() and CCScene::node() should be realized in their derived classes. The realization of node() is similar, we construct two macros to make the realization more essier: LAYER_NODE_FUNC and
SCENE_NODE_FUNC. To use the two macros, init() must be realized in the derived classes.

But everything is completed according to the Port Tips.

This program can run very well in win32, but I meet the error during I complie it into android platform.

error.JPG (95.3 KB)


the error shows that “GameOverScene.h:22: undefined reference to `vtable for GameOverScene’”,
does you class name(class GameOverScene : public cocos2d::CCScene) spell wrong?


or you could change the code as follows(remove the semicolon):
GameOverScene():_layer(NULL) {}; => GameOverScene():_layer(NULL) {}


Hey alpha, I posted an answer earlier today but it seems that it disappeared. Anyway, the issue it that you did not add the GameOverScene file to the makefile.

To do that you need to edit the android/jni/helloworld/ file and update the LOCAL_SRC_FILES definition to include the newly created GameOverScene.cpp file:

LOCAL_SRC_FILES := main.cpp …/…/…/Classes/AppDelegate.cpp …/…/…/Classes/HelloWorldScene.cpp …/…/…/Classes/GameOverScene.cpp

I posted it here as well:



any one is successful?


android 版本 楼上那个是旧版本的修改,在cocos2d-1.0.1-x-0.11.0版本中,要在HelloWorld/Classes/ 中加入 新场景文件的声明
LOCAL_SRC_FILES := AppDelegate.cpp HelloWorldScene.cpp GameOverScene.cpp