Linux learning tool Cygwin under windows

  
 

cygwin is a Unix simulation environment running on a Windows platform. It is a free software developed by cygnus solutions. (The company has developed a lot of good things, notably eCos, but it has been acquired by Redhat). It is very useful for learning the unix/linux operating environment, or porting applications from Unix to Windows, or doing some special development work, especially using the gnu tool set for embedded system development on Windows. With the growing popularity of embedded system development in China, more and more developers are interested in cygwin. This article will introduce it.

1 Mechanism cygnus first improved the development tools such as gcc, gdb, and gas, so that they can generate and explain the target files of win32. Then they have to port these tools to the windows platform. One solution is to make significant changes to the source code of these tools based on the win32 api, which obviously requires a lot of work. Therefore, they took a different approach —— they wrote a shared library (that is, cygwin dll), which encapsulates unix-style calls (such as fork, spawn, signals, select, sockets, etc.) that are not in win32 api. Inside, that is, they wrote a simulation layer of the Unix system library based on the win32 api. Thus, by linking the source code of these tools to this shared library, you can use the cross compiler on the unix host to generate a set of tools that can run on the Windows platform. Based on these development tools ported to the Windows platform, cygnus gradually ported other tools (nearly need to modify the source code, only need to modify their configuration scripts) to port the software. In this way, running bash and development tools and user tools on the windows platform feels like working on Unix. Is a good Linux learning tool! ! For a more detailed description of the cygwin implementation, please refer to http://cygwin.com/cygwin-ug-net/highlights.html.

2. Installation and setup cygwin 2.1 Installation To install the online version of cygwin, you can Http://cygwin.com, click "Install Cygwin Now!". This will first download a GUI installer called setup.exe, which can be used to download a complete cygwin. Follow the instructions on each screen for easy installation. 2.2 Environment Variables Before starting bash, you should set some environment variables. Cygwin provides a .bat file with the most important environment variables set. It is the safest way to start bash with it. This .bat file is installed in the root directory where cygwin is located. Feel free to edit this file. The CYGWIN variable is used to make multiple global settings for the cygwin runtime system. At the beginning, you can set CYGWIN or set it to tty under the dos box before executing bash. Set C:\\> set CYGWIN=tty notitle glob

PATH variable is used by cygwin application Search for a list of paths to the savvy files. When a cygwin process starts, the variable is converted from the windows format (e.g. C:\\WinNT\\system32; C:\\WinNT) to the unix format (e.g., /WinNT/system32:/WinNT). If you want to be able to use the cygwin toolset without 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. It is recommended to define this variable before executing bash. When the cygwin process starts, the variable is also converted from the windows format to the unix format. For example, the value of HOME on the author's machine is C:\\ (dos the command set HOME to see his value, set HOME=XXX can be performed. Set), use echo $HOME in bash, the value is /cygdrive/c. The TERM variable specifies the terminal type. If it is set up by the US, it will automatically be set to cygwin. LD_LIBRARY_PATH is used by the cygwin function dlopen() as a list of paths to search for .dll files. This variable is also converted from windows format to unix format. Most Cygwin applications do not use dlopen, so this variable is not needed. 2.3 Changing the maximum storage capacity of cygwin The default memory allocated by the Cygwin program does not exceed 384 MB (program+data). In most cases, you do not need to modify this limit. However, if you need more real or virtual memory, you should modify the HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER section of the registry. Tian Jia a DWORD key heap_chunk_in_mb and set its value to the required memory limit, the unit is decimal MB. This can also be done with regtool in cygwin. An example is as follows: regtool -i set /HKLM/Software/Cygnus\\ Solutions/Cygwin/heap_chunk_in_mb 1024 regtool -v list /HKLM/Software/Cygnus\\ Solutions/Cygwin

3. Using cygwin This section talks about cygwin and The difference between traditional Unix systems. 3.1 Mapping Path Names 3.1.1 Introduction cygwin supports both win32 and posix-style paths. The path separator can be either a forward slash or a backslash. UNC path names are also supported. (In the network, UNC is a way to determine the location of the file. With this method, the user can not care about the physical location of the storage device, which is convenient for the user. In Windows
OS
In Novell Netware and other operating systems
, this specification has been used to replace the local naming system. In UNC, we don't care what disk (or volume) the file is on, don't care about this disk ( Or volume where the server is located. We can access the file in the following format: \\\\servername\\sharename\\path\\filename sharename is sometimes also referred to as the logical identity of the volume or storage device where the file is located, but used Its purpose is to prevent users from having to care about the physical location of these volumes or storage devices.) Operating systems (such as linux) that conform to the posix standard do not have the concept of a drive letter. All absolute paths start with a slash, not a drive letter (like c:). All file systems are subdirectories of them. 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 specifically maintains an internal posix view for the win32 file system, allowing these programs to run correctly under Windows. In some cases, cygwin will use this mapping to convert between win32 and posix paths. 3.1.2 cygwin mount table The mount program in cygwin is used to map win32 drive letters and network share paths to cygwin's internal posix directory tree. This is a similar concept 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 uses a drive letter as a subdirectory of other paths. The path mapping information is stored in the current user's cygwin mount table, which is in the Windows registry. This way, when the user logs in 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 is a system-wide mount table. Each cygwin user's installation table inherits from the system table. The system table can only be modified by a user with appropriate permissions (admin of windows nt). The current user's mount table can be seen in the registry "HKEY_CURRENT_USER/Software/Red Hat, Inc./Cygwin/mounts v". The system table exists under HKEY_LOCAL_MACHINE. The posix root path/default points to the system partition, but you can use the mount command to redirect 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 at both /c and /, cygwin will convert C:/foo/bar to /c/foo/bar. If the mount command is called without any arguments, the current set of Cygwin installation points will be listed. Out. In the example below, the c drive is the POSIX root and the d drive is mapped to /d. In this case, the root is a system-wide installation point that 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, use umount to remove the mount point. When Cygwin can't convert a win32 path to a posix path based on an existing installation point, cygwin will automatically convert it to a mount point under the default posix path /cygdrive. For example, if Cygwin accesses Z:\\ Foo, and the Z disk is not currently in the installation table, then Z:\\ will be automatically converted to /cygdrive/Z. Each installation point can be given special properties. The automatically installed partition is displayed as “auto”installation. The mount point can also be selected as "textmode" or "binmode", which determines whether text files and binaries are handled in the same way. 3.1.3 Other path related information The cygpath tool provides the ability to convert win32-posix path format in a shell script. The HOME, PATH, and LD_LIBRARY_PATH environment variables are automatically converted from Win32 format to POSIX format when the cygwin process starts (for example, if there is an installation from the win32 path to the posix path, c:\\cygwin\\bin will be converted to /Bin).

Copyright © Windows knowledge All Rights Reserved