【转】解决使用NDK开发Android应用时.c/.cpp 中有错"syntax errors",不是真正的错误
转载自http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/
Your .c/.cpp file (native.cin my case) contains a lot of syntax errors which are not truly syntax errors. This is because Eclipse threats the project as a pure Java project. We have to convert the project into mixed Java & C/C++ project.
5) PressCtrl+n(or chooseFile->New->Other…from main menu) and selectConvert to a C/C++ Project.
This will convert your project into a mixed Java & C/C++ project rather than into pure C/C++ project (the name of the function is misleading).
ClickNext. Then choose your project and below chooseMakefile projectand– Other Toolchain –. ClickFinish.
After doing this Eclipse will ask you if you want to switch to C/C++ perspective. ChooseYesbecause otherwise you wouldn’t be able to set C/C++ build preferences.
6) Click on your project with right button and selectPropertiesor press Alt+Enter
Properties windows will appear. Here you have to configure use of ndk-build instead of make all command and set proper include paths.
7) ChooseC/C++ Buildand configurendk-buildas a build command
InBuilder settingsfillndk-buildintoBuild commandentry.You have to uncheckUse default build command. You also need to have ndk-build script in your PATH.
InBehavioursetting uncheckclean(ndk-build cleans project automatically on build and does not support separate clean command) and clear all text from build (ndk-builddoes not acceptallas a parameter.
ClickApplyto save settings.
8) ChooseC/C++ General->Paths and Symbolsand configure include path
InIncludestab chooseGNU CorGNU C++and clickAdd…button. Add path to include directory which is located inplatforms/android-4/arch/arm/usr/includesubdirectory of place where you’ve unpacked Android ndk. Include path depends on target for which you are compiling (android-4in my case — i.e. Android 1.6).
Finally clickApplyandOKand that is all. Now you can use all Eclipse power for editing your C/C++ sources. If you clickRunorDebugEclipse will compile C/C++ code as well as Java code and run it on device/emulator. However you will not be able to debug C/C++ code.
优质内容筛选与推荐>>