msys2安装后可以在windows下编译一些开源库的32,64位版本(当然可以做更多,而我主要用于编译不同指令集的库)。
下面简单记录下msys2的安装配置过程。
1. 下载msys2安装
http://sourceforge.net/projects/msys2/
2. 更新源
在安装目录下/etc/pacman.d/找到mirrorlist.mingw32,mirrorlist.mingw64,mirrorlist.msys文件,分别更新为修改为以下内容,请对号入座。
##
## 32-bit Mingw-w64 repository mirrorlist
##
## Primary
## msys2.org
Server = http://mirrors.ustc.edu.cn/msys2/mingw/i686/
Server = http://repo.msys2.org/mingw/i686
Server = http://downloads.sourceforge.net/project/msys2/REPOS/MINGW/i686
Server = http://www2.futureware.at/~nickoe/msys2-mirror/i686/
##
## 64-bit Mingw-w64 repository mirrorlist
##
## Primary
## msys2.org
Server = http://mirrors.ustc.edu.cn/msys2/mingw/x86_64/
Server = http://repo.msys2.org/mingw/x86_64
Server = http://downloads.sourceforge.net/project/msys2/REPOS/MINGW/x86_64
Server = http://www2.futureware.at/~nickoe/msys2-mirror/x86_64/
Server = http://mirror.bit.edu.cn/msys2/REPOS/
##
## MSYS2 repository mirrorlist
##
## Primary
## msys2.org
Server = http://mirrors.ustc.edu.cn/msys2/msys/$arch/
Server = http://repo.msys2.org/msys/$arch
Server = http://downloads.sourceforge.net/project/msys2/REPOS/MSYS2/$arch
Server = http://www2.futureware.at/~nickoe/msys2-mirror/msys/$arch/
修改完成后通过命令pacman -S Syu更新,更详细的可以看pacman help,差不多更新后即可。
2.安装开发环境
在win开始菜单打开MinGW 32-bit或者64-bit,通过pacman安装32、64位gcc开发环境。
pacman -S mingw-w64-x86_64-toolchain mingw-w64-i686-toolchain
通过以上安装已经可以build,在安装目录下有mingw32、mingw64两个文件夹,分别为32、64bit环境需要的编译工具集,不需要另外去下载mingw-32、mingw-64安装。
其他软件的安装使用pacman -S 名称即可,比如pacman -S make。
3. 怎么编译
msys2为默认的64位编译环境,对64bit支持比32bit友好,下面以编译x264库为例。
64位版本:
开始菜单打开minGW 64-bit,进入到x264代码目录,输入以下内容:
./configure --prefix=./x64
这样make后生成是64位版本,mingw比msys,minGW生成的文件不会依赖libgcc*库,当然你也可以在msys下使用静态库,但MinGW避免了这样的折腾。
32位版本:
同64bit版本,这里打开MinGW 32-bit,工具已经对32bit, 64bit做好很好的隔离,分别打开build即可,千万不要折腾。
!!!!使用上面64bit命令不会生成32bit makefile!!!!,而且会提示‘no working C compile not found.’,这也是我说的对32bit支持不够友好的地方。
使用以下命令:
./configure --prefix=./x86 --host=mingw32
完成后你会看到platform:X86
防止忘却所以记录。本文有些内容为其他博客摘录,也许有的地方与您的问题可能不同,感谢所有乐于奉献的人!