user1103138
user1103138

Reputation:

how to import and edit C++ code in eclipse using ndk?

Scenario: I have run and compiled an existing c++ code of cocos2d-x on android emulator using eclipse and NDK (CDT and Sequoyah are installed)(c++ code edited outside the eclipse). but, not able to edit c++ code or debug during runtime.

If I open a c++ (main.cpp) file, the project gets contaminated with errors. main.cpp is a file having java as well as c++ code in it. and already included in my project. (closing the project and then reopening it solves the errors for the time being)

Problems are:

1) how to open existing c++ files in a working android project?

2) how to tell eclipse that it's a mixed code/project of c++ as well as java. and not an error

thanks.

Upvotes: 2

Views: 3396

Answers (2)

Horyun Lee
Horyun Lee

Reputation: 1093

Most solution is provided by enobayram, however I cannot get content assistance like comment by @25061987 while programming in eclipse.

I think this is not good solution to get the assistance, though it works well.

  1. go to project preferences->C++ Generel->Paths and Symbols -> source Location
  2. select link folder
  3. Link to folder in the file system.
  4. Add "cocos2dx, cocosdenshion" folders of "your COCOS2DX_ROOT"

Or Try this way http://jpsarda.tumblr.com/post/26000816688/integrate-cocos2d-x-c-into-an-android-application he copied every sources...

Upvotes: 3

enobayram
enobayram

Reputation: 4708

In order to tell eclipse that it's a mixed project, while in C++ perspective, go to new->Convert to C/C++ project. It's a misnomer, it makes it a mixed project.

In order to let it find the included files, go to project preferences->C++ Generel->Paths and Symbols. There you can add the include folders for C/C++ (separately). The folders you need are

{Android NDK install dir}/sources/cxx-stl/{the stl that you're using if you're using it}/include

and

{Android NDK install dir}/platforms/Android[yourAPIlevel]/arch-arm/usr/include/android.

BTW. I was following some tutorial for this process, and they've also recommended going to C/C++ build, and doing the following:

  • uncheck "Use default build command"
  • change build command to ndk-build (we'll come back to that)
  • remove "all" from the text field next to "Build(Incremental Build)"
  • uncheck clean

This way, you can also build from eclipse. And it's really nice because that way you can also simply press "Run" and it will compile the C++ code, put the .dll (or .so) in the right place, install, and run. One little detail though. I think this is with newer versions of android-ndk that you have to say make APP=yourappname at the android-ndk installation root. So, that ndk-build in eclipse doesn't work. In order to trigger make in the right place, you can simply use make -C PATHTOYOURNDKINSTALLATION APP=yourappname as the build command in eclipse.

Upvotes: 5

Related Questions