Debug Cocos2d-x C + + code with Eclipse (write + True machine Debug, discard vs)

Source: Internet
Author: User

http://blog.csdn.net/tt5267621/article/details/8940768

Prerequisites:

First read this article: http://blog.csdn.net/tt5267621/article/details/8941084 (first ecplise already can compile cocos2d-x see this article)

    • You have downloaded the coccos2d-x and NDK and will build_native.sh compile the Cocos2d-x project with Eclipse
Installing the NDK Plugin

English good students can directly see the official instructions using the NDK plugin, here I briefly translated

    1. Open Eclipse, select Help->install New software in the menu ...
    2. Pop-up window in the first box "work with:" followed by inputhttps://dl-ssl.google.com/android/eclipse/
    3. Wait a moment, and the following will come out "Developer Tools" and "NDK Plugins", all selected, Next, agree agreement, etc after installation, restart Eclipse
    4. After eclipse restarts, go to ECLIPSE->PREFERENCES->ANDROID->NDK and set up your NDK directory here, like mine, which I set to/android/android-ndk-r8e
    5. Installation Complete
Import an example game under the Cocos2d-x directory

Here I use cocos2d-2.1rc0-x-2.1.3/samples/Cpp/SimpleGame this little game as an example to illustrate.

Let's say your eclipse is clean, that is, the Package Explorer bar on the left is empty.

    1. Import Libcocos2d-x to Eclipse, right-click the Package Explorer blank area, import->existing Android Code into Workspace, and then in the next window root directory where you navigate to cocos2d-2.1rc0-x-2.1.3/cocos2dx/platform/android/java this directory, select LIBCOCOS2DX, Import
    2. Follow the method above to importcocos2d-2.1rc0-x-2.1.3/samples/Cpp/SimpleGame/proj.android
    3. Now there are two items in eclipse: Libcocos2dx,simplegame
Setup uses Ndk-build to compile

Because we do not use build-native.sh to compile, so we have to get the resource file in the Android project assets, specifically, the cocos2d-2.1rc0-x-2.1.3/samples/Cpp/SimpleGame/Resources following all the files copied to the cocos2d-2.1rc0-x-2.1.3/samples/Cpp/SimpleGame/proj.android/assets following

Ready to work.

    1. In Eclipse's Package Explorer, right-click on the Simplegame project and select "Properties" to open the project properties box
    2. Set Tool Chain Editor as follows
    3. Set the Ndk-build command again, for ndk-build NDK_DEBUG=1 , OK, close the dialog box
    4. This time, you choose Project->build All, there will be an error, meaning that the Ndk_module_path setting is not correct
    5. Here we do not set Ndk_module_path, because set it will let us not debug C + + code, solve the above problem is: the compilation process needed to copy the library to the system default Ndk_module_path, follow me to do
    6. Copy these 4 directories under the cocos2d-2.1rc0-x-2.1.3 directory cocos2dx,CocosDenshion,extensions,external to your ndk's sources directory, take my computer for example, is/android/android-ndk-r8e/sources
    7. Copy all of the cocos2d-2.1rc0-x-2.1.3/cocos2dx/platform/third_party/android/prebuilt directories into the sources directory of the NDK
    8. So we copy the directory to the NDK's sources directory. cocos2dx,CocosDenshion,extensions,external, libcurl,libjpeg,libpng,libtiff,libwebp
    9. Back to eclipse, project->build all again, should compile successfully
Modify the project file structure so that the CDT can recognize our C + + files

In order to give C + + a breakpoint, we have to modify the current project file structure

    1. Move cocos2d-2.1rc0-x-2.1.3/samples/cpp/simplegame/classes directory to cocos2d-2.1rc0-x-2.1.3/samples/cpp/simplegame/ Proj.android/jni below
    2. Modify the Cocos2d-2.1rc0-x-2.1.3/samples/cpp/simplegame/proj.android/jni below the android.mk, put the original

In Android.mk:

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

Revision changed to

LOCAL_SRC_FILES := hellocpp/main.cpp                Classes/AppDelegate.cpp                Classes/HelloWorldScene.cpp                 Classes/GameOverScene.cppLOCAL_C_INCLUDES := $(LOCAL_PATH)/Classes    

That is, to point the file to the correct location

Project->build all compile project, should be able to compile successfully

Debugging
    1. We give the HelloWorldScene.cpp file in the classes directory the Cctouchesend method next breakpoint, so that after the game runs, click on the screen should be able to trigger our breakpoint
    2. Connect your phone to your computer, right-click Simplegame, choose Debug as->android Native Application
    3. If you need to select a phone, choose the one you want to debug
    4. After the game runs up, touch the screen and you can see

Eclipse automatically switches to the debug interface, and the success of the breakpoint down, and the variable can be in the right window to view the Debug button on the interface is no longer said, is to continue to execute, step into what a few, find out how to know

enjoy!

[Original article, reprint please specify]




PS: In the above operation we copied a lot of cocos2dx files to the NDK directory below, a bit cumbersome to do, so the directory is to avoid to set Ndk_module_path, if once set up Ndk_module_path, will make debugging not line, There may be a better way, if you know, or if you have any questions, you can leave a comment directly under the article.

Debug Cocos2d-x C + + code with Eclipse (write + True machine Debug, discard vs)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.