Cygwin--unix/linux simulation Environment [GO]

Source: Internet
Author: User
Tags posix system echo

Cygwin is a UNIX-like simulation environment that runs on the Windows platform and is the free software developed by Cygnus Solutions (the company has developed a number of useful tools, notably Ecos, but is now Redhat acquired). It is useful for learning unix/linux operating environments, porting applications from UNIX to Windows, or doing some special development work, especially for embedded system development on Windows using the GNU toolset. With the growing popularity of embedded system development in China, more and more developers have been interested in Cygwin.1 Introduction Cygwinis a collection of many software that was originally developed by Cygnus Solutions and is used on various versions of Microsoft Windows to run UNIX class systems. The main purpose of Cygwin is to port the software on POSIX systems (such as Linux, BSD, and other Unix systems) to Windows by recompiling (Note: I can develop on windows and then migrate to Linux). Cygwin porting works better on Windows NT, Windows 2000, Windows XP, and Windows Server 2003, and is relatively poor on Windows 95 and Windows 98. Cygwin is maintained by Red Hat and so on. [1]cygwin is a UNIX simulation environment running on the Windows platform, the free software developed by Cygnus Solutions (the company has developed a lot of good things, famous and Ecos, but has now been Redhat acquired). It is useful for learning unix/linux operating environments, porting applications from Linux to Windows, or doing some special development work, especially for embedded system development on Windows using the GNU toolset. With the growing popularity of embedded system development in China, more and more developers have been interested in Cygwin.2 development history Cygwin began in 1995 as a project of Steve Chamberlain, a Cygnus engineer. Windows NT and Windows 95 used COFF as the target code, while GNU already supported x86 and COFF, as well as the C-language library newlib. In this way, at least theoretically, GCC redirects can be used as cross compiler, resulting in executable programs that can run on Windows. In later practice, this was soon realized. The next question is how to boot the compiler in a Windows system, which requires a sufficient emulation of UNIX to allow the GNU configure Shell script to run so that it uses a shell like bash, which requires fork and standard I/O. Windows has similar functionality, so the Cygwin library only needs to make translation calls and manage private data, such as file descriptors. 1996 years later, other engineers joined in because they saw that Cygwin could provide Cygnus embedded tools on Windows systems (the previous scenario was to use DJGPP). Particularly appealing is that Cygwin can implement Three-way cross-compile, for example, build on a sun workstation, thus forming windows-x-mips Cross-compiler, which is much faster than simply compiling on a PC. Since 1998, Cygnus has started to offer the Cygwin package as a product.3 Composition Cygwin includes a library that implements POSIX system invoke APIs under the Win32 system, and a GNU development toolset (such as GCC, GDB) for simple software development, and some common programs under UNIX systems. In 2001, the X Window System was added. There is also a library called MinGW, which works with the Windows local MSVCRT library (Windows API). MinGW consumes less memory, hard disk space, and can link to any software, but its implementation of the POSIX specification does not have a complete Cygwin library. Unfortunately, Cygwin does not support Unicode. In fact, in addition to the current Windows system and the OEM codepages (for example, a Russian user, his codepages is CP1251 and CP866, not koi8-r, ISO/IEC 8859-5, UTF-8, etc.), Cygwin is not supported for other character sets. Red Hat rules that the Cygwin library complies with the GNU general public License, but can also be linked to free software that complies with open source definitions. Red Hat also has a costly license agreement, so you can redistribute it using the proprietary software of the Cygwin library.4 working mechanism Cygnus first improved the development tools such as Gcc,gdb,gas, enabling them to generate and interpret Win32 's target files. They then transplanted the tools to the Windows platform. One scenario is to drastically modify the source code of these tools based on the Win32 API, which obviously requires a lot of work. So they took a different approach-they wrote a shared library (that is, the Cygwin DLL), encapsulating UNIX-style calls (such as fork,spawn,signals,select,sockets, etc.) that are not in the Win32 API, which means They wrote a mock layer of a UNIX system library based on the Win32 API. This way, you can use the cross-compiler on a UNIX host to build a toolset that can run on a Windows platform as long as the source code of these tools is connected to the shared library. Based on these porting to the development tools on the Windows platform, Cygnus is gradually porting other tools (almost without the need to modify the source code, only to modify their configuration scripts) software to Windows. This way, running bash and development tools and user tools on the Windows platform feels like working on Unix.5 Installation installationCygwin's installation files are easy to find through Google. At present, the domestic website has "network installation version" and "Local installation Version" two kinds. The standard distribution should be the network installation version. There is no big difference between the two, the installation process is described below. Step1. After downloading, click Install File (setup.exe) to install, the first screen is the GNU Copyright Note, click "Next (N)", Environment VariablesBefore you start running bash, you should set up some environment variables. Cygwin provides a. bat file that has the most important environment variables set up. It's the safest way to start bash with it. This. bat file is installed in the root directory where Cygwin is located. You can edit the file freely. The Cygwin variable is used to make various global settings for the Cygwin runtime system. At the beginning, you can set it to ttyc:\> set Cygwin=tty notitle globpath variable as the CYGWIN application as a list of paths to search for the CYGWIN file, either without setting it up or before executing bash in a DOS box similar to the following. When a Cygwin process starts, the variable is removed from the Windows format (e.g. C:\WinNT\system32; C:\WinNT) into the UNIX format (e.g.,/winnt/system32:/winnt). If you want to use the Cygwin toolset when you're not running bash, the path should at least contain x:\cygwin \ bin, where X:\cygwin is the Cygwin directory on your system. The home variable is used to specify the home directory, and it is recommended to define the variable before bash executes. When the Cygwin process starts, the variable is also converted from Windows to UNIX format, for example, on the author's machine The value of home is \ C (DOS command set home can see his value, set home=xxx can be set), in Bash with echo $ Home, the value of the/CYGDRIVE/C.TERM variable specifies the terminal type. If it is not set, it is automatically set to Cygwin. Ld_library_path is Cygwin function dlopen () as a list of paths to search. dll files, which is also converted from Windows format to UNIX format. Most Cygwin applications do not use Dlopen, so the variable is not required. Enter the installation mode selection screen. Step2. The installation mode has "install from Internet", "Download form Internet", "Install from Local Directory" three kinds. The Install form Internet is installed directly from the Internet for faster speeds. In the Select Mirror page, you can use some Chinese image sources to increase the speed. [2]
Mirror Source address
description network protocol
mirrors.ustc.edu.cn China University of Science and technology open source software image
mirrors.neusoft.edu.cn Dalian Neusoft Information Institute Network Center Open Source Mirror station http/ftp
mirrors.163.com NetEase Open Source Mirror station mirrors.sohu.com Sohu Open Source Mirror station http
If you and the network speed is not fast, or if you want to save the downloaded installation files, the next time no longer download the direct installation, you should choose "Download form Internet", download the installed files (about 40M). In fact, the so-called "local Installation", but also others from the Internet download all the files after the package, applicable to the situation of poor network. Step3. The next step is to select the path where the installation destination and installation source files are located, and then go to the path where you chose the installation package. Here is the key part of the installation. Select the components you want to install here, and you will not be able to work without natural installation. You can use the search box to find the software you want to install. For example, it is not possible to compile software without installing GCC, and so on. + All default+ Admin default....+ Devel default+ Editors Default .... As shown, you can change its state by double-clicking on one of the nodes of the TreeView, such as default, Install, Uninstall, reinstall four states. Defaults are default states, and the default state of many tools is not installed. Here I chose the "all" on the back of the default point install, all installed, so as not to trouble. (Note: Here the tree control and win under the different, you try the pilot at all on the point and in all this line behind the default point, there will be a different response) Step4. Click Next to install successfully. It will automatically create a shortcut on your desktop. OK, here's my Linux journey. Double-click the Cygwin shortcut to enter the system. Let's start by introducing a few simple Linux commands. PWD shows the current path CD changes the current path, no parameters when entering the corresponding user's home directory LS lists the files in the current directory. This command has n multiple parameters, such as Ls-alps list current system process kill kill a process mkdir build directory rmdir Delete directory rm Delete file MV File Rename or directory rename man online help less Display the last few lines of the file because most of the commands in Linux below have many parameters, they can be used in combination. So, whenever you do not or remember to use that parameter, the switch, you can use the man to find, for example, I want to find how to use the LS, you can type the M LS system echo information as follows: LS (1) FSF ls (1) namels-list directory Contentssynopsisls [OPTION] ... [FILE] ... Descriptionlist information about the FILEs (the current directory bydefault). Sort entries Alphabetically If none Of-cftusuxnor--sort.-a,--alldo not hide entries starting with. A,--almost-alldo n OT list implied. and.. -B,--escapeprint octal escapes for nongraphic characters--block-size=sizeuse size-byte blocks 6 User Guide IntroductionCygwin supports both Win32 and POSIX-style paths, and the path delimiter can be a forward slash or a backslash. UNC path names are also supported. (In a network, a UNC is a way to determine the location of a file, which allows users to not care about the physical location of the storage device and facilitates user use.) In the Windows operating system, Novell NetWare and other operating systems have used this specification to replace the local naming system. In a UNC, we don't have to worry about what disk (or volume) the file is on, and don't care where the disk (or volume) resides on the server. We can access the file in the following format: \ \ server name \ share name \ path \ file name Share name is also sometimes referred to as the logical identity of the volume or storage device where the file is located, but it is used to make it unnecessary for users to care about the physical location of these volumes or storage devices. A POSIX-compliant operating system, such as Linux, does not have the concept of a drive letter. All absolute paths begin with a slash, not a drive letter (such as C:). All file systems are sub-directories. For example, two hard disks, one of which is the root and the other may be under the/disk2 path. Because programs on many UNIX systems assume a single POSIX file system structure, Cygwin specifically maintains an internal POSIX view of the Win32 file system that allows these programs to run correctly under Windows. In some necessary cases, Cygwin uses this mapping to convert between Win32 and POSIX paths.Cygwin mount tableThe Mount program in Cygwin is used to map the Win32 drive and network share paths to the internal POSIX directory tree of Cygwin. This is a concept similar to the typical UNIX mount program. For those who are unfamiliar with UNIX and have a Windows background, the Mount program is very similar to the earlier DOS command join, which is to put a letter as a subdirectory of the other path. The path mapping information is stored in the Cygwin Mount table of the current user, which is also in the registry of Windows. This information is then removed from the registry the next time the user logs in. The Mount table is divided into two types, with the exception of each user-specific table and the system-wide mount table, which is inherited from the system table for each Cygwin user's installation table. System tables can only be modified by users who have the appropriate permissions (Windows NT administrators). The current user's Mount table can be seen under the registry "Hkey_current_user/software/red Hat, Inc./cygwin/mounts v".system Tablesexists under HKEY_LOCAL_MACHINE. The POSIX root path/default points to the system partition, but you can use the Mount command to point back to any path in the Windows file system. Cygwin the longest prefix in the Mount table is always used when generating POSIX paths from the Win32 path. For example, if C: is installed simultaneously in/C and/,cygwin will convert C:/foo/bar to/c/foo/bar. If you call the Mount command without any parameters, the Cygwin current set of installation point collections are all listed. In the following example, the C drive is the POSIX root, and the D disk is mapped to/d. In this case, the root is a system-wide installation point that is visible to all users and/d only to the current user. c:\> mountf:\cygwin\bin On/usr/bin type System (binmode) F:\cygwin\lib on/usr/lib type System (Binmode) F:\cygwin on/ Type System (Binmode) E:\SRC on/usr/src type System (binmode) c:on/cygdrive/c type User (Binmode,noumount) e:on/cygdrive The/E type User (Binmode,noumount) can also use the Mount command to add a new mount point and remove the mount point with Umount. When Cygwin cannot convert a Win32 path to a POSIX path based on an existing installation point, Cygwin automatically converts it to an installation point that is under the default POSIX path/cygdrive. For example, if Cygwin accesses Z:\foo and the Z-disk is not currently in the installation table, the z:\ is automatically converted to/cygdrive/z. You can assign special properties to each installation point. Automatically installed partitions are displayed as "Auto" installations. The mount point can also be selected as "TextMode" or "Binmode", which determines whether text files and binaries are handled the same way.path-related informationThe Cygpath tool provides the ability to convert win32-posix path formats in shell scripts. The HOME, PATH, and LD_LIBRARY_PATH environment variables are automatically converted from the WIN32 format to the POSIX format when the Cygwin process starts (for example, if there is an installation from that Win32 path to the POSIX path, the c:\cygwin\ Bin to/bin).Changing storage capacityThe Cygwin program can allocate less than 384 MB (program+data) of memory by default. In most cases, you do not need to modify this restriction. However, if more actual or virtual memory is needed, you should modify the HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER section of the registry. Add a DWORD key HEAP_CHUNK_IN_MB and set its value to the required memory limit, in decimal megabytes. You can also use the Regtool in Cygwin to complete this setting. Examples are as follows: Regtool-i set/hklm/software/cygnus\ solutions/cygwin/heap_chunk_in_mb 1024regtool-v List/hklm/software/cygnus \ Solutions/cygwin1.7 version and Eclipse issuesEclipse is a well-known IDE that is powerful and can be used for c\c++ development. Eclipse Development c\c++, need to use the CDT plug-in, you can use Cygwin to develop some Linux porting Windows development, or cross-compiling (Microsoft VC compiler does not provide this feature). Today's more popular Android NDK development, if you have to use Cygwin under the Windows platform. and the CDT plugin uses the registry to discover where the Cygwin software is installed, and if it is developed with Eclipse software, it is convenient to install without any environment variables when installing Cygwin. However, as the Cygwin update to the 1.7,CDT plugin began to work abnormally, the most obvious two symptoms were: 1.console no output, 2. Ctrl-click, many standard objects cannot find the corresponding header file. Workaround: Open eclipse,windows->preferences->c\c++->debug->source Lookup Path, click Add, add a Path Mapping, the name can be arbitrarily taken, For example Cygwin Path Mapping; Assuming that Cygwin is installed on the C drive,/cygdriver/c is mapped to \ n, after saving, restart Eclipse, previous CTRL click, the console output will be OK. This method comes from the CDT plugin FAQ, the specific URL is see extended reading. The principle is very simple, because Eclipse is a cross-platform compiler, so the CDT plugin is a UNIX-style path when looking for files on disk, so it doesn't work on windows, does a path mapping, The path to the disk where the Cygwin is located is mapped to a Windows-style path, and the CDT can normally discover the header file. version 7 released October 21, 2012, Cygwin 1.7.17 released-Linux development tools under Windows. [3] The latest version can be found on the official website cygwin.com.

Cygwin--unix/linux simulation Environment [GO]

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: info-contact@alibabacloud.com 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.