Search code examples
javaandroidc++eclipsecocos2d-x

Adding cpp files to cocos2d-x project android project


I've followed this tutorial http://www.raywenderlich.com/33750/cocos2d-x-tutorial-for-ios-and-android-getting-started, and managed to create an android hello world project in cococs2d-x. Now when I add anything to my classes directory and try to use them, I get errors like

make: *** [obj/local/armeabi/libgame.so] Error 1
undefined reference to 'ConstAndStats::getDevice()' 

How should I fix these problems, and add the already working codes (in Xcode) for my eclipse project?


Solution

  • This kind of error may appear if you add a class to the classes directory but forget to add it to the Android.mk file from the jni folder. Add something like this:

    LOCAL_SRC_FILES := hellocpp/main.cpp \
              ../../Classes/YourClass.cpp \
              ../../Classes/YourLastClass.cpp