Cygwin是在Windows操作系统上仿真Linux操作系统,是一个在Windows平台上运行的Linux模拟环境,它使用动态链接库*.dll
来实现,简单来说Cywin是一个Windows的软件。
Cygwin最初将gcc
、gdb
、gas
等开发工具进行改进,使其能够生成并解释win32
的目标文件,然后将这些工具移植到Windows平台,一种方案是基于win32 api对工具源代码进行大幅修改,显然这需要大量工作。他们采取了另一种不同的方式,编写一个共享库即cygwin dll
,将win32 api中没有UNIX风格的调用如fork
、spawn
、signal、
select、
sockets`...封装到里面。也就是说,Cywin是基于win32 api编写的一个UNIX系统库的模拟层。只要将这些工具的源代码和共享库连接起来,就可以使用UNIX上的交叉编译器来生成在Windows平台上运行的工具集。以这些移植到Windows平台上的开发工具为基础,Cygnus又逐步将其他工具移植到了Windows平台上,这样在Windows平台上运行Bash和开发工具,感觉和在UNIX上工作一样。
下载安装Cygwin
安装Cygwin是选择必备的安装包包括gcc
、wget
、tar
、gawk
、bzip2
...,若没有安装过重新使用cygwin.exe
程序重新安装。
配置Cygwin环境变量
Cygwin的根目录下的可执行程序路径包含:\bin
、\sbin
、\usr\local\bin
,将这些目录的物理路径配置到环境变量path
中。
$ make -v
GNU Make 3.82.90
Built for i686-pc-mingw32
Copyright (C) 1988-2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ gcc -v
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --with-gmp=/mingw --with-mpfr --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --enable-libgomp --disable-libvtv --enable-nls
Thread model: win32
gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)
$ php -v
安装wget
下载wget-latest.tar.gz
并将其移动到home
目录下,解压软件后进入wget目录进行编译安装。
$ cd wget
$ ./configure
$ make
安装apt-cyg
包管理工具
$ wget https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg
$ chmod +x apt-cyg
$ mv apt-cyg /usr/local/bin/
$ opt-cyg install nano
Cygwin命令
$ ps
$ ps -aW
$ df
$ vim ~/.bashrc
export LANG="zh_CN.GBK"
export OUTPUT_CHARSET="GBK"
apt-cyg
工具命令
$ apt-cyg install <package names>
$ apt-cyg remove <package names>
$ apt-cyg update
$ apt-cyg list [pattern(s)]
$ apt-cyg show <pattern(s)>
$ apt-cyg search <commands or files>