Cygwin User Guide

zhaozj2021-02-16  85

1 Introduction

Cygwin is a UNIX simulation environment running on a Windows platform, which is the free software developed by Cygnus Solutions (the company has developed a lot of good things, and the famous ECOS is now available). It is very useful for learning UNIX / Linux operating environments or transplants from UNIX to Windows, or for certain special development work, especially using GNU tools to embed system development on Windows. As embedded systems are developing in China, more and more developers have interested in Cygwin. This article will be introduced.

2 mechanism

Cygnus first improved the development tools such as GCC, GDB, GAS, enabling them to generate and explain the Win32 target file. Then they want to transplant these tools to the Windows platform. One solution is based on Win32 API's source code for these tools, which clearly requires a lot of work. Therefore, they have taken a different way - they wrote a shared library (that is, Cygwin DLL), encapsulated in the Win32 API (such as Fork, Spawn, Signals, SELECT, SOCKETS, etc.) That is, they wrote an analog layer of a UNIX system library based on Win32 API. This way, just connect these tools and this shared library together, you can use the cross-compiler on the UNIX host to generate a toolset that can run on the Windows platform. Based on these development tools on the Windows platform, Cygnus gradually puts other tools (almost no need to modify the source code, just modifying their configuration scripts) software transplanted to Windows. This way, running Bash and development tools on the Windows platform, user tools, feel like working on UNIX.

For more detailed description of Cygwin implementation, please refer to http://cygwin.com/cygwin-ug-net/highlights.html.

3 installation settings Cygwin

3.1 Installation

To install the online version of Cygwin, you can go to http://cygwin.com, click on "Install Cygwin Now!". This will download a GUI installer called Setup.exe and use it to download a complete Cygwin. The instructions of each screen can be easily installed.

3.2 Environmental variables

You should set some environment variables before starting Bash. Cygwin provides a .bat file, which has set the most important environment variable. It is the safest way to start Bash by it. This .bat file is installed under the root of Cygwin. This file can be edited freely.

Cygwin variables are used for a variety of global settings for Cygwin runtime systems. At the beginning, you can set it to TTY under the DOS box without setting Cygwin or using the following format in the DOS box.

C: /> set cygwin = Tty Notitle Glob

The PATH variable is used by the Cygwin application as a list of paths to search for identity files. When a Cygwin process is started, the variable is converted from the Windows format (E.G. C: / Winnt / System32; C: / Winnt) into UNIX format (E.G., / WinNT / System32: / Winnt). If you want to use the Cygwin toolset when you don't run Bash, the PATH should include x: / cygwin / bin, where x: / cygwin is the CygWin directory in your system.

Home variable is used to specify the primary directory, it is recommended to define this variable before executing BASH. When the Cygwin process is started, the variable is also converted from the Windows format to UNIX format, for example, the value of HOME on the author's machine is C: / (DOS command set home can see his value, set home = xxx can do Setting), with Echo $ HOME in Bash, its value is /cygdrive/c.term variable specifies the terminal type. If the US is set to it, it will be automatically set to Cygwin.

LD_LIBRARY_PATH is used as a path list of a search .dll file as a search .dll file, which is also converted to UNIX format from the Windows format. Most Cygwin applications do not use DLOPEN, so this variable is not required.

3.3 Change the maximum storage capacity of Cygwin

The Cygwin program defaults that can be allocated without more than 384 MB (Program Data). This limit does not need to be modified in most cases. However, if you need more actual or virtual memory, you should modify the HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER segment of the registry. Tian family a DWORD key Heap_chunk_in_mb and sets its value to the required memory limit, and the unit is a decimal MB. You can also complete this setting with RegtoE in Cygwin. The example is as follows:

Regtool -i set / hklm / soft / cygnus / solutions / cygwin / heap_chunk_in_mb 1024

Regtool -V List / HKLM / Software / CYGNUS / SOLUTIONS / CYGWIN

4 use Cygwin

This paragraph tells the difference between Cygwin and the traditional UNIX system.

4.1 Map path name

4.1.1 Introduction

Cygwin also supports Win32 and POSIX-style paths, and the path separator can be a front slash or a backslash. Also supports UNC pathname. (In the network, UNC is a method of determining file locations, using this method user can not care about the physical location of the storage device, which is convenient for users. In Windows operating system, Novell NetWare, and other operating systems have been used This specification is replaced with a local naming system. In the UNC, we don't have to care about the file on what disk (or volume), do not care about this disk (or volume) where the server is located. We can access the file in the following format. :

// Server Name / Shared Name / Path / File Name

The shared name is sometimes referred to as a logical ID of the volume or storage device in which the file is located, but the purpose of using it is to allow the user to do not care about the physical location of these volumes or storage devices. )

Compliance with the POSIX standard operating system (such as Linux) does not have the concept of a disk. All absolute paths are starting with a slash instead of a disk (such as C :). All file systems are the subdirectory. For example, two hard drives, one of which are roots, and the other may be under the / disk2 path.

Because the programs on many UNIX systems assume that there is a single POSIX file system structure, CygWin specializes in the internal POSIX view of the Win32 file system, so that these programs can run correctly under Windows. In some cases, Cygwin uses this mapping to perform conversion between Win32 and POSIX paths.

4.1.2 CYGWIN MOUNT Table

The mount program in Cygwin is used to map the Win32 drive and the network shared path to the internal POSIX directory tree of Cygwin. This is a concept similar to a typical UNIX MOUNT program. For those who are unfamiliar with Unix, the Mount program and the early DOS command Join are very similar, that is, the subdirectory of one drive as another path. Path mapping information is stored in the Cygwin Mount table of the current user, this mount table is in the registry of Windows. Thus, when the user is logged in next time, this information is removed from the registry. The Mount is divided into two, except for each user-specific table, and the system-wide mount table, each CygWin user's installation table is inherited from the system table. The system table can only be modified by a user who has the right permissions (administrator) of Windows NT.

The current user's MOUNT table can be seen under the registry "HKEY_CURRENT_USER / SOFTWARE / Red Hat, Inc./cygwin/mounts v". System table

There is HKEY_LOCAL_MACHINE.

POSIX root path / default points to system partitions, but you can use the mount command to redirect to any path to the Windows file system. When Cygwin generates a POSIX path from the Win32 path, it always uses the longest prefix in the MOUNT table. For example, if C: is mounted at the same time in / c and /, Cygwin will convert C: / foo / bar into / c / foo / bar.

If you call the mount command without any parameter, you will list all the Cygwin's current installation points. In the example below, the C drive is the POSIX root, and the D disk is mapped to / d. In this example, the root is a system-wide mount point, which is visible to all users, and / D is only visible to the current user.

C: /> mount

F: / 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 / E TYPE USER (Binmode, Noumount)

You can also use the mount command to add a new installation point, and remove the installation point with umount.

When Cygwin converts a Win32 path to the POSIX path according to an existing installation point, Cygwin automatically converts it to a mount point in the default POSIX path / cygdrive. For example, if Cygwin Access Z: / Foo, and the z disk is currently not in the installation table, then z: / will be automatically converted into / cygdrive / z.

Special properties can be given to each mounting point. The auto-installed partition is displayed as "Auto" installation. The installation point can also choose "TextMode" or "binmode", which determines whether the text file and the binary are handled in the same way.

4.1.3 Other paths related information

The CygPath tool provides the ability to perform Win32-POSIX path format conversion in the shell script.

Home, path, and ld_library_path environment variables are automatically converted from Win32 format to POSIX format when the Cygwin process is started (for example, if there is a installation from the Win32 path to the POSIX path, C: / cygwin / bin will be converted into / bin).

转载请注明原文地址:https://www.9cbs.com/read-12671.html

New Post(0)