android 为什么需要cygwin

本文介绍了Cygwin作为在Windows平台上运行的Unix模拟环境,如何与Android NDK结合使用,实现从Unix/Linux操作环境的学习、应用程序移植,以及在Windows上构建和编译C/C++代码的过程。特别关注了NDK版本更新后,无需Cygwin即可在Windows上构建NDK源代码的方法。

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

 1、cygwin简介   

Cygwin是许多软件的集合,最初由Cygnus Solutions开发,用于各种版本的Microsoft Windows上,运行UNIX类系统。Cygwin的主要目的是通过重新编译,将POSIX系统(例如Linux、BSD,以及其他Unix系统)上的软件移植到Windows上. 

    cygnus当初首先把gcc,gdb,gas等开发工具进行了改进,使他们能够生成并解释win32的目标文件。然后,他们要把这些工具移植到windows平台上去。一种方案是基于win32 api对这些工具的源代码进行大幅修改,这样做显然需要大量工作。因此,他们采取了一种不同的方法——他们写了一个共享库(就是cygwin dll),把win32 api中没有的unix风格的调用(如fork,spawn,signals,select,sockets等)封装在里面,也就是说,他们基于 win32 api写了一个unix系统库的模拟层。这样,只要把这些工具的源代码和这个共享库连接到一起,就可以使用unix主机上的 交叉编译器来生成可以在 windows平台上运行的工具集。以这些移植到windows平台上的开发工具为基础,cygnus又逐步把其他的工具(几乎不需要对源代码进行修改,只需要修改他们的配置脚本)软件移植到windows上来。这样,在windows平台上运行bash和开发工具、用户工具,感觉好像在unix上工作。

2、NDK和cygwin

由于NDK编译代码时必须要用到make和gcc,所以你必须先搭建一个linux环境, cygwin是一个在windows平台上运行的unix模拟环境,它对于学习unix/linux操作环境,或者从unix到windows的应用程序移植,非常有用。通过它,你就可以在不安装linux的情况下使用NDK来编译C、C++代码了。

3.r7版本以上NDK可以不使用cygwin

http://www.kandroid.org/ndk/docs/CHANGES.html

http://developer.android.com/tools/sdk/ndk/index.html#Revisions

You can now build your NDK sources on Windows *without* Cygwin. Simply call the script 'ndk-build.cmd' from the Windows cmd.exe command-line, when in your project path. The script takes exactly the same arguments than the original ndk-build one.

Note that the Windows NDK package comes with its own prebuilt binaries for GNU Make, Awk and other tools required by the build, i.e. you shouldn't need to install anything else to get a working build system.

IMPORTANT: ndk-gdb doesn't work. You still need Cygwin to debug at the moment! This feature is still very experimental, but feel free to try it and report issues on the public forum (android-ndk@googlegroups.com) or the public bug databse (http://b.android.com). Note that all samples and unit tests succesfully compile with it.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值