Configure the android ndk environment in Windows: Install and update cygwin...

Source: Internet
Author: User
Tags ruby on rails ibm support

Recently, I want to see the JNI of Android and I don't want to switch back to Linux. So I have to choose windows + cygwin + ndk,

When you start to install the cygwin environment, you generally do not know how to install it. Even after installation, you will find that many packages do not exist ,,,

It seems that all the packages in the devel category need to be installed on the Internet ,,

Fortunately, I read an article on the Internet to install and update cygwin. repost it and record it ,,,

Original article address:




If you are a loyal reader of this column, you should be familiar with a lot of UNIX dialect. It is strange for new users to say "Redirect outputs with pipelines", "Kill processes", and "use wildcards", but you should be familiar with these statements.

UNIX itself is also called. IBM mainframe users speak a variety of line words with the letter "Z", such as ibm z/OS and system Z9 Virtual Machine (z/Vm); Nested system developers use the word "ECOs; many other UNIX styles, such as Linux, FreeBSD, Sun Solaris, and Mac OS X, are also mentioned in the chat. Modern information technology uses a variety of dialects, just like the story of the babeta in the Bible.

Of course, there are also many people talking about Windows terms, although most people only master simple words such as "pointing and clicking. After 20 years of development, most Windows users have forgotten the old dos terminology.

However, compared with Unix shell, WindowsCOMMANDThe functionality of the utility is really poor; therefore, Unix users generally think that Windows is a frustrating platform. For UNIX software developers who are used to using a rich set of command line tools, Windows is especially awkward. For Unix developers, using Windows is like a stranger to a foreign country.

Fortunately, cygwin (see references) provides a world that everyone is familiar with in a Windows environment, just as Americans have found McDonald's in France.

Cygwin is a UNIX-like shell environment for Windows. It consists of two components: a Unix API library, which simulates many features provided by the UNIX operating system, as well as the bash shell rewrite version and many UNIX utilities, they provide familiar Unix Command Line interfaces. The previous component is a Windows dynamic link library (DLL ). The latter component is a set of cygwin DLL-based programs, many of which are compiled with unmodified UNIX source code. They work together to provide a familiar Unix environment.

In this session, we will install cygwin, discuss its command line interface (CLI), and build open source code not included in the standard cygwin release, how easy it is to migrate UNIX applications (at least a part of UNIX applications) to this simulated environment.

Version details

At the time of writing this article, the current version of cygwin DLL is 1.5.25-15. Cygwin can be installed in any recent windows business version, except Windows CE. (However, cygwin will not support Windows 95, Windows 98, and Windows ME in the future ). The example and graph provided in this article are based on Windows XP Professional with Service Pack 3 (SP3). The computer used is an apple MacBook in coherence mode and uses parallels version 3.0.

Install cygwin

Unlike other software described here, cygwin uses the Windows installer. In the cygwin setup.exe file, you can reinstall the software and add, modify, or upgrade the cygwin configuration components.

Open your browser on Windows and download the cygwin installer by accessing the The installer itself is very small (about KB) because most cygwin software is downloaded during installation. After the download is complete, follow these steps to install cygwin:

  1. Run the installer. Figure 1 shows the cygwin welcome screen.

    Figure 1. The first dialog box that appears during cygwin Installation

  2. ClickNextGo to the next screen and select the installation type to be executed.
  3. ClickInstall from Internet.
  4. ClickNextAnd select an installation directory.

    The configuration and installation window is shown in figure 2.

    Figure 2. cygwin Installation Options

    In most cases, the recommended installation options are suitable and can be customized, but pay attention to the following points:

    • Do not install cygwin in the Windows root directory (such as C.It is best to install cygwin in its own subdirectory, such as the default directory (C:/cygwin) or C:/program files/cygwin. (The target directory you selected will be the root directory of the simulated Unix environment./. For example, if you install it in C:/cygwin, the virtual/usr/bin is actually C:/cygwin/usr/bin ).
    • ForInstallOption, do not selectJust me.
    • SetDefault text fileType is setUNIXTo improve compatibility with existing files stored on other UNIX machines.
  5. ClickNext.

    In the next window, select a directory for storing the data required by cygwin.Do not select the cygwin directory selected in the previous step.If possible, create or select a directory on a drive with at least 1 GB of free space.

  6. Click againNext, And select the Internet connection type to use. Select direct connection.
  7. Click againNext.

    Wait a moment, cygwin will download the current image site list and let you select an image site, as shown in figure 3. If you are not sure which site to choose, select a site with a relatively close geographical location.

    Figure 3. Select an installation site that you think is reliable or geographically close

    After a short delay, the installer displays a complete list of available categories and packages. Figure 4 shows part of a category. Click the plus sign (+) Expand the corresponding category. Click the "loop" icon to cycle between the SKIP (ignore this package) and all available versions of the package. If cygwin provides multiple versions of a utility, select an instance that meets your needs. By the way, if Column B is selected, the binary package is downloaded. If column S is selected, the source code is also downloaded.

    Figure 4. select the most suitable package and instance

    There are more than 1,000 packages available in cygwin, so you should select only the type and package you need. (Installation of all cygwin packages will occupy more than 800 mb of disk space ). You can add the entire category or package at any time: simply re-run the cygwin installer. (You can also use the same installer to delete or update packages at any time ). Search for the cygwin package list (see references) and check whether your favorite Unix utility is available in cygwin.

  8. After selecting the required tool, clickNextThe download process starts!

    The progress bar displays the download progress, total download progress, and disk usage of each package. Figure 5 is a screen screenshot taken during installation on my test computer.

    Figure 5. cygwin downloads a large number of software, so please be patient

    Finally, install the software and (optional) add shortcuts to the Start menu and desktop. ClickFinish.

  9. Use the Start Menu or double-click the cygwin icon (if you have added these shortcuts) to start cygwin. You can also execute the cygwin script in the cygwin directory (such as C:/cygwin. BAT ).

    Figure 6 shows the first time cygwin was started: it creates your home directory and executes the shell Startup File, showing a prompt. Now you can run the Unix Command!

    Figure 6. Now you can use Unix commands in windows!

    For example, tryls -aOrtype touch. The next command indicatestouchIs an executable file/usr/bin/touch.

Back to Top

Take advantage of UNIX in Windows (and vice versa)

Cygwin almost completely simulates a Unix shell in windows. In fact, it combines these two operating systems well. For example, you can rundf -hCommand to display the free disk space on the "UNIX" machine. Figure 7 shows the result.

Figure 7. Is it a Unix File System on Windows or a Windows File System on UNIX?

As mentioned above, the cygwin installation directory serves as the root directory of the virtual UNIX system. Cygwin maps subdirectories in the installation directory to the Unix directory. It provides a Windows Drive in the form of a separate volume, such as/cygwin/C. You can use this virtual path to start Windows programs. Enter/cygwin/c/Program/ Files/Internet/ Explorer/IEXPLORE.EXEStart Windows Internet Explorer from the command line. (You can also use the tab key to automatically expand the path element ).

By the way, if you want to convert a Windows path name to an equivalent UNIX path name or vice versa, try the built-in command.cygpath. By default,cygpathGenerate a Unix path name. Use-wOption to generate a Windows path.

$ cygpath -w /cygwin/c/Program/ Files/Internet/ Explorer/IEXPLORE.EXEc:/Program Files/Internet Explorer/IEXPLORE.EXE


It also helps to communicate with other features of these two environments:

  • Cygwin provides its ownlpr(/Usr/bin/lpr instead of Windows LPR. EXE), which can be printed directly from a simulated Unix environment. You only need to set the printer environment variable to cygwin UNC such as // server/printer_name or // server/printer_name. Both forward and reverse slashes can be used, as can be seen elsewhere in cygwin.
  • Used in cygwinln -sThe created symbolic link is interpreted as a shortcut in windows. Similarly, Windows shortcuts are interpreted as symbolic links in cygwin. Therefore, you can use the windows shortcut with parameters to start Unix commands.
  • Because cygwin provides a complete bash shell, you can use all of the above compatible features (and other features) to write Unix shell scripts to maintain windows!

    For example, you can use UnixfindSearch for data on the drive. Note that spaces are often used in Windows file names. To keep the complete file name (Remember, Unix parameters are separated by spaces), be sure to usefind -print0Andxargs -0.

Back to Top

How to update and expand cygwin

As mentioned above, cygwin categories and packages can be added, deleted, and updated at any time by running the cygwin installer. Let's add several software development kits to build programs from the source code just like on a traditional UNIX system.

Run the cygwin setup.exe application again, and then use the previous dialog boxes until the Select Packages window is reached. See figure 4. Expand the devel category and use the loop control to select the maximum version of the following package:

  • autoconf2.1
  • automake1.10
  • binutils
  • gcc-core
  • gcc4-core
  • gdb
  • pcre
  • pcre-devel

After the selection is made (to meet the dependency, other packages may be automatically selected), clickNextStart update. As before, the download and installation process takes some time (the Development Kit is usually quite large ).

During this period, open a browser and download GNUwgetThe latest source code of the utility. (wgetIs a command line tool that can download anything. For more information about this tool, see references ). Use cygwin to copy the file to the main directory of cygwin and expand the compressed file. Listing 1 shows the content of the compressed file.

Listing 1. Contents of the wget-1.11.4.tar

$ cp /cygdrive/c/Documents/ and/ Settings/Martin/My/ Documents/wget-1.11.4.tar ~$ tar xzvf wget-11.4.tarwget-1.11.4/wget-1.11.4/AUTHORSwget-1.11.4/NEWSwget-1.11.4/COPYINGwget-1.11.4/configure.batwget-1.11.4/ChangeLogwget-1.11.4/ChangeLog.READMEwget-1.11.4/msdos/wget-1.11.4/msdos/ChangeLogwget-1.11.4/msdos/Makefile.DJ...wget-1.11.4/src/cookies.cwget-1.11.4/src/http.hwget-1.11.4/src/log.hwget-1.11.4/src/sysdep.hwget-1.11.4/src/alloca.cwget-1.11.4/src/getopt.cwget-1.11.4/src/gnu-md5.hwget-1.11.4/src/ftp.cwget-1.11.4/config.subwget-1.11.4/config.guess$ 


When cygwin download and installation are complete, clickFinish. Now we can build from source codewgetUtility.

$ cd wget-1.11.4$ ./configureconfigure: Configuring for GNU wget 1.11.4...creating po/Makefile$ makegcc -I. ...$ make install.../usr/bin/install -c -m 644 ./wget.1 /usr/local/share/man/man1/wget.1$ type wget/usr/local/bin/wget


To test this new utility, run it in cygwin and downloadwgetSource code:

$ /usr/local/bin/wget


A new source code compressed file will be generated later. Using the cygwin installer to obtain utilities from the cygwin repository is the easiest way, but you can also build the downloaded or your own source code in cygwin. In cygwin, you can use a full set of Unix development tools, including the most popular scripting language.

If you do not like Microsoft Visual Studio or other Windows development tools, you can even use the Unix compiler and tool in cygwin to build a Native Windows Win32 application. (These applications are not running on UNIX. To run Windows applications on UNIX, consider using wine. For more information, see references ).

Back to Top


Cygwin is not a perfect UNIX simulation environment, but it is already quite good. The core components are well-documented and especially convenient. They describe limitations and security risks in simulated DLL. If you want to migrate complex UNIX packages to cygwin, please refer to the developer guide (see references) to assess whether cygwin support can meet your API needs.

The best feature of cygwin is probably its integration with windows. Using cygwin and its Unix Command Line to manipulate the system can greatly increase productivity. We recommend that you include subdirectories in Windows's program files in your shell PATH variable so that you only need to enter the program name to start any binary program in the path.

Even better, cygwin can manage multiple jobs in the same window. Press Control-Z to pause a running job. EnterbgAndfgRun jobs on the backend and foreground respectively. EnterjobsManage the job list. Of course, cygwin can also redirect the input and output, and send the output of one command to another through the pipeline.

Cygwin is really good.




  • For more information, see the original article on the developerworks global site.
  • Dialog Unix: read other articles in this series.
  • Learn more about cygwin features.
  • Read the official guide cygwin user's guide.
  • Check the cygwin package list.
  • Read the cygwin api reference to learn about UNIX compatibility and how to migrate to cygwin.
  • Learn more about Unix shell.
  • For more information about wine, wine is an open-source Windows API implementation.
  • AIX and Unix zone: the "Aix and Unix zone" on developerworks provides a wealth of information related to all aspects of Aix system management that you can use to extend your UNIX skills.
  • Getting started with AIX and Unix: visit the "getting started with AIX and Unix" page to learn more about AIX and UNIX.
  • Summary of Aix and Unix topics: the AIX and Unix area has introduced many technical topics for you and summarized many popular knowledge points. We will continue to launch many related hot topics later. To facilitate your access, we will summarize all the topics in this area here, it makes it easier for you to find the content you need.
  • Browse books on these and other technical topics in the technical bookstore.

Obtain products and technologies

  • Download cygwin installer for Windows.
  • Download and learnwget.


  • Join the developerworks blogs community.
  • Participate in Aix and Unix forums:
    • AIX Forum
    • AIX forum for developers
    • Cluster Systems Management
    • IBM Support Assistant Forum
    • Performance Tools Forum
    • Virtualization Forum
    • More AIX and Unix forums
    • AIX networking

About the author

Martin Streicher is a free Ruby on Rails developer andLinux magazine. Martin graduated from Purdue University and obtained a computer science degree. He has been engaged in programming UNIX systems since 1986. He likes to collect art and toys.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.