【转】解决使用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.

优质内容筛选与推荐>>
1、deepmind
2、java提高篇(八)----详解内部类
3、QQ聊天气泡(图片拉伸不变样)、内容尺寸定制(高度随字数、字体而变)
4、结构体数组初始化三种方法,转载
5、python之字符串方法


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号