eclipse in android,Compile C/C++ In Eclipse for Android

本文详细介绍了如何在Eclipse环境下配置C/C++开发环境,包括Eclipse IDE的选择安装、Cygwin的完整安装、CDT的添加以及Android NDK的集成。特别强调了Cygwin的本地全包下载和环境变量设置的重要性,以及NDK-Build的配置和使用。此外,还提供了显示Cygwin中文的方法,并给出了一个测试项目的创建步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Software Version:

A.Eclipse IDE for C/C++ Developers + Cygwin

①Install Eclipse IDE for C/C++ Developers.

②Install Cygwin.Important step!You had better download the full package and install from local.Installing from Internet always failed and may lost file!

The first time I install it from the Internet ,but it occured a file failure and I ignore it.Then ,holy shit!!! I spend 2 days to debug the errors result from the file failure!!So remember that you had better install the full package and from the local.

0818b9ca8b590ca3270a3433284dd417.png

click the "Install" after "All".

Install/Download from Internet.If the warning “Download Incomplete,Try again? ” comes out or it hangs on a certain progress,you can cancel it and repeat the download steps.Remember two points:

Ⅰ.Select the same download website with the last time.

Ⅱ.Installing type,select ”Reinstall“ not ”install“.(may needn't)

Then you can continue the download progress or you have to install from 0.

0818b9ca8b590ca3270a3433284dd417.png

I download it first for a night and then install it for a day.A whole day!

Probably you have to set theenvionment variable PATH。PATH should include x:\cygwin\bin,x:\cygwin is your cygwin install folder。

My is f:\cygwin.Then PATH=f:\cygwin\bin.

③Restart Eclipse,File->New->C++ Project

0818b9ca8b590ca3270a3433284dd417.png

click Finish,Build it first and then run it.

B.Eclipse Classic+ Cygwin +CDT

①Install Eclipse Classic 4.2.

②Install CDT for Eclipse.

Open the CDT download page,you will see the following content:

0818b9ca8b590ca3270a3433284dd417.png

The p2 software repository is the address you should access in Eclipse.Help->Install New Software,click Add button and input the address:

0818b9ca8b590ca3270a3433284dd417.png

click OK,then you will see the next:

0818b9ca8b590ca3270a3433284dd417.png

click next to install them.

However,it hanged at this progress for a long time:

0818b9ca8b590ca3270a3433284dd417.png

Then I canceled  it ,and clicked the cdt-master-8.1.0.zip of  pictrue ,wanting to download it first and install it from local directory.

0818b9ca8b590ca3270a3433284dd417.png

clickArchive to select the local zip file.

Finally,I installed the CDT successfully.

③Install Cygwin.The same with Part A②.

④Restart Eclipse,File ->New -> Others,and you'll see C/C++ project.

C.Eclipse Classic + Cygwin +CDT + NDK -> so Lib

①②③ The same with part B①②③.

④Install NDK.Download the zip file and unzip it to the destination folder.my is D:\Android\android-ndk-r8

Edit file \cygwin\home\user_name\.bash_profile,if you can't find the file in this location,copy the cygwin\etc\skel\.bash_profileto here,add the following to the end:

0818b9ca8b590ca3270a3433284dd417.png

# Android NDK

NDK=/cygdrive/

export NDK

My:

ndk=/cygdrive/D/Android/android-ndk-r8

export ndk

0818b9ca8b590ca3270a3433284dd417.png

ndk is a custom name ,you can change it.

Save and restart cygwin.Go to D:\Android\android-ndk-r8\samples\hello-jni\jni :

cd $ndk/samples/hello-jni/jni

0818b9ca8b590ca3270a3433284dd417.png

execute command:$ndk/ndk-build

0818b9ca8b590ca3270a3433284dd417.png

Pay attention to these content of google document:

Required development tools

For all development platforms, GNU Make 3.81 or later is required. Earlier versions of GNU Make might work but have not been tested.

A recent version of awk (either GNU Awk or Nawk) is also required.

For Windows, Cygwin 1.7 or higher is required.The NDK will not work with Cygwin 1.5 installations.

If you installed the wrong version,you may get the error of the following pictrue:

0818b9ca8b590ca3270a3433284dd417.png

⑤CreateNDK Builder for Eclipse.

Right click your project->Properties->Builders->New->Program:

Main  location:the path of file bash.exe in cygwin/bin.

workingdirectory:the path of cygwin/bin.

arguments:--login -c "cd /cygdrive/d/Workspace2/hello&&$ndk/ndk-build"

/cygdrive/d/Workspace2/hello is the absolute path of yourandroid project.

if you can't input the argument or it can't be recognized,make sure that you have added the path of ndk (D:\Android\android-ndk-r8) to the environment PATH.

0818b9ca8b590ca3270a3433284dd417.png

In label Refresh,specific the folder needed to refresh when compilation end.Choose libs,create it if none.

0818b9ca8b590ca3270a3433284dd417.png

About the label Build Options,use to set the folder needed to monitor.Run the builder when the content of the folder changed.

Specify working set... choose the folder of the c/c++ code.

0818b9ca8b590ca3270a3433284dd417.png

Completed! you can use the builder in your android project.

D.Show Chinese in Cygwin

Right Click->Options:

0818b9ca8b590ca3270a3433284dd417.png

Set the character set to GBK,not UTF-8

E.A Project For Test

①Create a empty android project.

②Create jni folder to contain c/c++ code.

③Create libs folder to contain generated libs.

④Write your c/c++ code in jni.

My:hello.cpp

inttest() {return 5;

}

⑤Write your Android.mk file.you can copy it from the ndk sample project.

⑥Press "Ctrl+S" to save it and the lib will be generated automatically.

0818b9ca8b590ca3270a3433284dd417.png

⑦Generate the lib which can be used in android.

In order to use the lib in Android, you have to modify the C/C++ code to coordinate with android.

0818b9ca8b590ca3270a3433284dd417.png

If the package name or activity name not coordinate with c/c++ method name,UnsatisfiedLinkError may occurs.

To use the lib:

0818b9ca8b590ca3270a3433284dd417.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值