Cygwin User Guide ZT

Source: Internet
Author: User
Tags glob posix
According to the cygwin user guide, I hope to help you. Indicate errors.

1 Introduction
Cygwin is a UNIX simulation environment running on the Windows platform. It is a free software developed by Cygnus solutions. (The company has developed many good things, famous for its ECOs, but it is now acquired by RedHat ). It is used to learn Unix/Linux operations
It is very useful for environments, Unix-to-Windows applications, or some special development work, especially for embedded system development on Windows using the GNU tool set. As embedded system development becomes increasingly popular in China, more and more developers are interested in cygwin. This article will introduce it.

2 Mechanism
Cygnus first improved development tools such as GCC, GDB, and gas so that they can generate and explain Win32 target files. Then they will port these tools to the Windows platform. One solution is to greatly modify the source code of these tools based on Win32 APIs, which obviously requires a lot of work. Therefore, they adopt a different method-they write a shared library (cygwin. DLL) to encapsulate Unix-style calls (such as fork, spawn, signals, select, and sockets) not found in Win32 APIs. That is to say, they wrote a simulation layer for UNIX system libraries based on Win32 APIs. In this way, as long as the source code of these tools and the shared library are connected together, you can use the cross compiler on the unix host to generate
Tool set running on Windows platform. Based on these development tools transplanted to the Windows platform, Cygnus gradually uses other tools (almost no need to modify the source code,

You only need to modify their configuration scripts) and Port the software to Windows. In this way, running bash, development tools, and user tools on Windows seems to work on UNIX. For a more detailed description of cygwin implementation, please refer to the http://cygwin.com/cygwin-ug-net/highlights.html
3. Install cygwin3.1
To install cygwin for the network version, go to the http://cygwin.com and click "Install cygwin now! ". This example will first download a GUI installer called setup.exe, which can be used to download a complete cygwin. The installation can be easily performed according to the instructions on each screen. 3.2 Environment Variables
Before Running Bash, you should set some environment variables. Cygwin provides a. BAT file with the most important environment variables configured. It is the safest way to start bash. The. BAT file is installed in the root directory of cygwin. You can edit the file as needed. The cygwin variable is used to perform multiple global settings for the cygwin runtime system. At the beginning, you can choose not to set cygwin or set it to TTY in the DOS box in a format similar to the following before executing bash.
C:/> set cygwin = tty notitle glob

Path
The variable is used by the cygwin application as the path list for searching intellectual files. When a cygwin process is started, the variable is converted from Windows format (e.g. C:/winnt/system32; C:/WINNT) to Unix format (e.g .,
/Winnt/system32:/WINNT ). If you want to use the cygwin tool set without running bash, path should contain at least X:/cygwin/bin, where X:/cygwin is the cygwin directory in your system. The Home variable is used to specify the main directory. We recommend that you define this variable before executing bash. When the cygwin process is started, the variable is also converted from the Windows format to the Unix format. For example, the home value on the author's machine is C: /(Set Home = xxx can be seen by running the doscommand set home.) In bash, use echo $ home to check whether the value is/cygdrive/C.
The term variable specifies the terminal type. If beauty sets it, it is automatically set to cygwin. LD_LIBRARY_PATH is used by the cygwin function dlopen () as the path list for searching. DLL files. This variable is also converted from windows to Unix. Most cygwin applications do not use dlopen, so this variable is not required. 3.3 change cygwin's maximum storage capacity
By default, the cygwin program can allocate up to 384 Mb of memory (Program + data ). In most cases, you do not need to modify this restriction. However, if you need more actual or virtual memory, you should modify the HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER Section of the Registry. Tian Jia has a DWORD key heap_chunk_in_mb and sets its value
Memory limit, in decimal MB. You can also use regtool in cygwin to complete this setting. Example:
Regtool-I set/HKLM/software/Cygnus/solutions/cygwin/heap_chunk_in_mb 1024
Regtool-V list/HKLM/software/Cygnus/solutions/cygwin

4. Use cygwin
This section describes the differences between cygwin and traditional UNIX systems. 4.1 Introduction to map pathnames 4.1.1
Cygwin supports both Win32 and POSIX paths. The path separator can be a forward slash or a backslash. UNC path names are also supported. (In the network, UNC is a method for determining the file location. With this method, you can ignore the physical location of the storage device, making it easier for you to use. In Windows, Novell Netware, and other operating systems, this specification has been used to replace the local naming system. In UNC, we do not need to care about the disk (or volume) where the file is located, or where the disk (or volume) is located. You can access files in the following format:
/Server name/share name/path/file name share name is also known as the logical identifier of the volume or storage device where the file is located, but the purpose of using it is to make users do not have to worry about the physical location of these volumes or storage devices .) POSIX-compliant operating systems (such as Linux) do not have a drive letter concept. All absolute paths start with a slash instead of a drive letter (such as C :). All file systems are subdirectories. For example, two hard disks, one of which is the root and the other may be in the/disk2 path. Because many programs on UNIX systems assume a single POSIX file system structure, cygwin maintains an internal POSIX view for Win32 file systems, make these programs run correctly in windows. If necessary, cygwin will use this ing to convert between Win32 and POSIX paths. 4.1.2 cygwin Mount table
The Mount program in cygwin is used to map Win32 drive letters and network shared paths to the internal POSIX directory tree of cygwin. This is similar to a typical UNIX mount program. For those who are unfamiliar with Unix and have a Windows background, the mount program is very similar to the early DOS command join, that is, to use a drive letter as a subdirectory of other paths. Path ing information is stored in the current user's cygwin Mount table, which is also in the Windows registry. In this way, when the user logs in for the next time, the information is retrieved from the registry. There are two types of Mount tables. In addition to each user-specific table, there are also system-specific Mount tables. Each cygwin user's installation table inherits from the system table. System tables can only be modified by users with appropriate permissions (administrators of Windows NT. The current user's Mount table can be seen in the Registry "HKEY_CURRENT_USER/software/Red Hat, NC./cygwin/mounts V. The system table exists in HKEY_LOCAL_MACHINE. POSIX root path/default point to system partition, but you can use the mount command to re-point to any path in 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 Installed in/C and/at the same time, cygwin will convert C:/Foo/bar to/C/Foo/bar. if the mount command is called without any parameters, the current set of installation points of cygwin will be listed. In the following example, drive C is a POSIX root, and drive D is mapped to/d. In this example, the root is a system-wide installation 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 use umount to delete the Installation Point. When cygwin cannot convert a Win32 path to a POSIX path based on an existing installation point, cygwin will automatically convert it to an installation point under the default POSIX path/cygdrive. for example, if cygwin accesses Z:/Foo and the Z disk is not in the installation table, Z:/will be automatically converted to/cygdrive/Z. you can assign special properties to each installation point. The automatically installed partitions are displayed as "Auto. You can also select "textmode" or "binmode" as the installation point. This attribute determines whether the text and binary files are processed in the same way. 4.1.3 other path information
The cygpath tool provides the ability to convert win32-posix path formats in shell scripts.
The environment variables home, path, and LD_LIBRARY_PATH will be automatically converted from Win32 to POSIX when the cygwin process starts (for example, if the installation from this Win32 path to POSIX path exists, c:/cygwin/bin to/bin ).


3. Install cygwin3.1
To install cygwin for the network version, go to the http://cygwin.com and click "Install cygwin now! ". This example will first download a GUI installer called setup.exe, which can be used to download a complete cygwin. The installation can be easily performed according to the instructions on each screen. 3.2 Environment Variables
Before Running Bash, you should set some environment variables. Cygwin provides a. BAT file with the most important environment variables configured. It is the safest way to start bash. The. BAT file is installed in the root directory of cygwin. You can edit the file as needed. The cygwin variable is used to perform multiple global settings for the cygwin runtime system. At the beginning, you can choose not to set cygwin or set it to TTY in the DOS box in a format similar to the following before executing bash.
C:/> set cygwin = tty notitle glob

Path
The variable is used by the cygwin application as the path list for searching intellectual files. When a cygwin process is started, the variable is converted from Windows format (e.g. C:/winnt/system32; C:/WINNT) to Unix format (e.g .,
/Winnt/system32:/WINNT ). If you want to use the cygwin tool set without running bash, path should contain at least X:/cygwin/bin, where X:/cygwin is the cygwin directory in your system. The Home variable is used to specify the main directory. We recommend that you define this variable before executing bash. When the cygwin process is started, the variable is also converted from the Windows format to the Unix format. For example, the home value on the author's machine is C: /(Set Home = xxx can be seen by running the doscommand set home.) In bash, use echo $ home to check whether the value is/cygdrive/C.
The term variable specifies the terminal type. If beauty sets it, it is automatically set to cygwin. LD_LIBRARY_PATH is used by the cygwin function dlopen () as the path list for searching. DLL files. This variable is also converted from windows to Unix. Most cygwin applications do not use dlopen, so this variable is not required. 3.3 change cygwin's maximum storage capacity
By default, the cygwin program can allocate up to 384 Mb of memory (Program + data ). In most cases, you do not need to modify this restriction. However, if you need more actual or virtual memory, you should modify the HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER Section of the Registry. Tian Jia has a DWORD key heap_chunk_in_mb and sets its value
Memory limit, in decimal MB. You can also use regtool in cygwin to complete this setting. Example:
Regtool-I set/HKLM/software/Cygnus/solutions/cygwin/heap_chunk_in_mb 1024
Regtool-V list/HKLM/software/Cygnus/solutions/cygwin

4. Use cygwin
This section describes the differences between cygwin and traditional UNIX systems. 4.1 Introduction to map pathnames 4.1.1
Cygwin supports both Win32 and POSIX paths. The path separator can be a forward slash or a backslash. UNC path names are also supported. (In the network, UNC is a method for determining the file location. With this method, you can ignore the physical location of the storage device, making it easier for you to use. In Windows, Novell Netware, and other operating systems, this specification has been used to replace the local naming system. In UNC, we do not need to care about the disk (or volume) where the file is located, or where the disk (or volume) is located. You can access files in the following format:
/Server name/share name/path/file name share name is also known as the logical identifier of the volume or storage device where the file is located, but the purpose of using it is to make users do not have to worry about the physical location of these volumes or storage devices .) POSIX-compliant operating systems (such as Linux) do not have a drive letter concept. All absolute paths start with a slash instead of a drive letter (such as C :). All file systems are subdirectories. For example, two hard disks, one of which is the root and the other may be in the/disk2 path. Because many programs on UNIX systems assume a single POSIX file system structure, cygwin maintains an internal POSIX view for Win32 file systems, make these programs run correctly in windows. If necessary, cygwin will use this ing to convert between Win32 and POSIX paths. 4.1.2 cygwin Mount table
The Mount program in cygwin is used to map Win32 drive letters and network shared paths to the internal POSIX directory tree of cygwin. This is similar to a typical UNIX mount program. For those who are unfamiliar with Unix and have a Windows background, the mount program is very similar to the early DOS command join, that is, to use a drive letter as a subdirectory of other paths. Path ing information is stored in the current user's cygwin Mount table, which is also in the Windows registry. In this way, when the user logs in for the next time, the information is retrieved from the registry. There are two types of Mount tables. In addition to each user-specific table, there are also system-specific Mount tables. Each cygwin user's installation table inherits from the system table. System tables can only be modified by users with appropriate permissions (administrators of Windows NT. The current user's Mount table can be seen in the Registry "HKEY_CURRENT_USER/software/Red Hat, NC./cygwin/mounts V. The system table exists in HKEY_LOCAL_MACHINE. POSIX root path/default point to system partition, but you can use the mount command to re-point to any path in 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 Installed in/C and/at the same time, cygwin will convert C:/Foo/bar to/C/Foo/bar. if the mount command is called without any parameters, the current set of installation points of cygwin will be listed. In the following example, drive C is a POSIX root, and drive D is mapped to/d. In this example, the root is a system-wide installation 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 use umount to delete the Installation Point. When cygwin cannot convert a Win32 path to a POSIX path based on an existing installation point, cygwin will automatically convert it to an installation point under the default POSIX path/cygdrive. for example, if cygwin accesses Z:/Foo and the Z disk is not in the installation table, Z:/will be automatically converted to/cygdrive/Z. you can assign special properties to each installation point. The automatically installed partitions are displayed as "Auto. You can also select "textmode" or "binmode" as the installation point. This attribute determines whether the text and binary files are processed in the same way. 4.1.3 other path information
The cygpath tool provides the ability to convert win32-posix path formats in shell scripts.
The environment variables home, path, and LD_LIBRARY_PATH will be automatically converted from Win32 to POSIX when the cygwin process starts (for example, if the installation from this Win32 path to POSIX path exists, c:/cygwin/bin to/bin ).

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.