MSYS2 + MinGW-w64 + Git + gVim 环境配置

輝夜(tadvent) posted @ 2014年9月27日 16:40 in 未分类 with tags gcc gvim Git MINGW MSYS2 Vundle , 30156 阅读

以前用 MSYS 的多,最近重装系统顺带把环境重新配一下,发现 MSYS2 挺顺手的。

一、安装 MSYS2

先装 MSYS2 的好处是之后可以将 $HOME 设为 /home/name/,再装其他 *nix 系工具时配置文件都会放在 MSYS2 的 /home/name 下,方便管理。

1. 到 http://sourceforge.net/projects/msys2/ 下载安装。

  安装位置设为 D:/develop/msys64

  添加环境变量 HOME 为 D:\develop\msys64\home\name,这个变量非常有用,后面配置要多次用到。

2. 运行 msys2_shell.bat

pacman -Sy

更新本地包数据

3. 升级核心包

pacman -S --needed filesystem msys2-runtime bash libreadline libiconv libarchive libgpgme libcurl pacman ncurses libintl

之后需要关闭所有 MSYS2 shell,然后运行 autorebase.bat

4. 升级其他包

pacman -Su

运行环境说明:

可以看到 MSYS2 有三个执行脚本,分别是 msys2_shell.bat、mingw32_shell.bat 和 mingw64_shell.bat,查看内容可以看到其中只有一行区别,即是设定 MSYSTEM 变量。这个变量在 /etc/profile 中会用到:

if [ -n "$MSYSTEM" ]
then
  case "$MSYSTEM" in
    MINGW32)
      PATH="/mingw32/bin:${MSYS2_PATH}:${PATH}"
      PKG_CONFIG_PATH="/mingw32/lib/pkgconfig"
      MANPATH="/mingw32/share/man:${MANPATH}"
      TERMINFO=/mingw32/share/terminfo:${TERMINFO}
    ;;
    MINGW64)
      PATH="/mingw64/bin:${MSYS2_PATH}:${PATH}"
      PKG_CONFIG_PATH="/mingw64/lib/pkgconfig"
      MANPATH="/mingw64/share/man:${MANPATH}"
      TERMINFO=/mingw64/share/terminfo:${TERMINFO}
    ;;
    MSYS)
      PATH="${MSYS2_PATH}:/opt/bin:${PATH}"
      PKG_CONFIG_PATH="/usr/lib/pkgconfig:/lib/pkgconfig"
      TERMINFO=/usr/share/terminfo
    ;;
    *)
      PATH="${MSYS2_PATH}:${PATH}"
    ;;
  esac
else
  PATH="${MSYS2_PATH}:${PATH}"
fi

可见,三个 .bat 的区别就是 PATH 的设置,mingw32_shell.bat 优先使用 msys64/mingw32 下的工具,mingw64_shell.bat 优先使用 msys64/mingw64 下的工具,而 msys2_shell.bat 两个都不使用,只用自身 msys 的工具。这么做的好处是当需要编译 32bit Target 的项目时使用 mingw32_shell.bat,64 bit 使用 mingw64_shell.bat,各套工具互不干扰。

二、安装 GCC

随便哪个 shell.bat 下都可以

1. 查看可用的安装包

pacman -Sl | grep gcc

可以看到以下三个

mingw32 mingw-w64-i686-gcc 4.9.1-3
mingw64 mingw-64-x86_64-gcc 4.9.1-3
msys gcc 4.8.2-2

分别对应于 msys 的三个 .bat 环境。这里先装第一个,其他类似。

2. 安装

pacman -S mingw-w64-i686-gcc

MSYS2 会自动将这个包装在 msys64/mingw32 下,从之前的分析可知只有 mingw32_shell.bat 会用到这个目录下的程序。

3. 运行

打开 mingw32_shell.bat 来试一下:

gcc --version
gcc.exe (Rev3, Built by MSYS2 project) 4.9.1
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

三、安装 Git

1. 下载 Git for Windows。安装过程选择 Git cheetah plug-inRun Git from Windows Command Prompt,这样 Vim 的 Vundle 插件可以调用 git。

由于安装 MSYS2 时已设置了 HOME 环境变量,Git 会自动将配置文件放在 HOME 下,将来在 MSYS2 中使用时共用一套配置,方便。

安装 MSYS2 的 git:

pacman -S git

2. 设置 autocrlf 为 input。

git config --global core.autocrlf input

由于设置了 HOME 环境变量,可以使 gvim 和 MSYS2 的 vim 共用一套配置文件:~/.vimrc,插件也可以统一放在 ~/.vim/ 下。在使用 Vundle 时,git clone 出的代码是 unix 换行符可以避免 MSYS2 vim 读取 Vundle 插件文件时出错。

3. KDiff3 用作 diff 和 merge 工具很方便,也一并装了吧。装好后配置 Git:

git config --global merge.tool kdiff3
git config --global mergetool.kdiff3.path "C:/Program Files/KDiff3/kdiff3.exe"

中间有空格也能正确处理。可以试一下 git mergetool 和 git difftool 看看是否配置正确了。为避免每次用 git difftool 时都提示确认,下面两行也可以设一下:

git config --global mergetool.prompt false
git config --global difftool.prompt false

四、安装 gVim 并配置 Vundle 进行插件管理

1. 安装 gVim 到 D:\develop\Vim,组件选择 full

2. 由于设置了 HOME 环境变量,就可以将 gvim 的配置统一放在 HOME 目录下

将 Vim/vimfiles 下的所有文件夹删除,在 ~/.vim 下新建 bundle 文件夹

3. 参考 Vundle.vim 的教程设置好 Git 的 Curl 脚本:

https://github.com/gmarik/Vundle.vim/wiki/Vundle-for-Windows

4. 将 gmarik/Vundle.vim git clone 到 ~/.vim/bundle 下:

cd ~/.vim/bundle
git clone https://github.com/gmarik/Vundle.vim.git

5. 继续参考 Vundle.vim 的教程修改 ~/.vimrc 文件,将内容添加到开头处。虽然是在 Windows 环境下使用 gvim,但由于设置了 HOME 环境变量,以下设置按 Lunix 配置更方便:

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

以后插件会自动安装在 $HOME/.vim/bundle 目录下。

6. 修改 .vimrc 添加要安装的插件包,然后在 gVim 中运行

:PluginInstall

7. 现在可以使用 :h vundle 来查看 Vundle 的帮助了。

五、其他配置

1. 将 gVim 目录加入 Path 环境变量,设置 Git 使用 gvim 作为默认 editor:

git config --global core.editor gvim

2. 要将常用工作目录映射到 MSYS2 的 ~ 下,可用 mount 命令(加入 .bash_profile 中):

mount -fo binary,noacl,posix=0,user D:/docs ~/docs

这样打开 MSYS2 shell 后直接 cd docs 即可进入常用工作目录。

3. 其他工具的安装类似,查看 pacman 手册即可。常用的:

列出可用的包

pacman -Sl

安装

pacman -S package-name

删除

pacman -R package-name

4. 将配置同步到 github 上!

  a. 新建 repository UserConfig,添加 .gitignore 文件,内容为 *,默认忽略所有文件。

  b. git clone 到本地

git clone https://github.com/tadvent/UserConfig.git

  c. 将其中的 .git 目录和 .gitignore README.md 文件移动到 ~/ 下。

  d. 新建 msys2 分支并添加要同步的文件,over~

git checkout -b msys2
git add -f .bash_profile .bashrc .gitconfig .vimrc
git commit
git push origin master msys2

 

Avatar_small
依云 说:
2014年10月01日 15:27

MSYS2 这个有意思~

Avatar_small
依云 说:
2014年10月01日 15:40

MSYS2 这个有意思~

sheao11 说:
2015年2月06日 17:27

请问博主,安装GCC
pacman -Sl | grep gcc
之后,显示文件有很多,如下:
mingw32 mingw-w64-i686-gcc 4.9.2-2
mingw32 mingw-w64-i686-gcc-ada 4.9.2-2
mingw32 mingw-w64-i686-gcc-ada-debug 4.9.1-3
mingw32 mingw-w64-i686-gcc-debug 4.9.1-3
mingw32 mingw-w64-i686-gcc-fortran 4.9.2-2
mingw32 mingw-w64-i686-gcc-fortran-debug 4.9.1-3
mingw32 mingw-w64-i686-gcc-libgfortran 4.9.2-2
mingw32 mingw-w64-i686-gcc-libgfortran-debug 4.9.1-3
mingw32 mingw-w64-i686-gcc-libs 4.9.2-2
mingw32 mingw-w64-i686-gcc-libs-debug 4.9.1-3
mingw32 mingw-w64-i686-gcc-objc 4.9.2-2
mingw32 mingw-w64-i686-gcc-objc-debug 4.9.1-3
mingw64 mingw-w64-x86_64-gcc 4.9.2-2
mingw64 mingw-w64-x86_64-gcc-ada 4.9.2-2
mingw64 mingw-w64-x86_64-gcc-ada-debug 4.9.1-3
mingw64 mingw-w64-x86_64-gcc-debug 4.9.1-3
mingw64 mingw-w64-x86_64-gcc-fortran 4.9.2-2
mingw64 mingw-w64-x86_64-gcc-fortran-debug 4.9.1-3
mingw64 mingw-w64-x86_64-gcc-libgfortran 4.9.2-2
mingw64 mingw-w64-x86_64-gcc-libgfortran-debug 4.9.1-3
mingw64 mingw-w64-x86_64-gcc-libs 4.9.2-2
mingw64 mingw-w64-x86_64-gcc-libs-debug 4.9.1-3
mingw64 mingw-w64-x86_64-gcc-objc 4.9.2-2
mingw64 mingw-w64-x86_64-gcc-objc-debug 4.9.1-3

其中像mingw-w64-i686-gcc-debug、mingw-w64-i686-gcc-ada-debug等不能安装,说是:
警告:无法解决 "mingw-w64-i686-gcc=4.9.1-3","mingw-w64-i686-gcc-debug" 的一个依赖关系
:: 因为无法解决依赖关系,以下软件包无法进行更新:
mingw-w64-i686-gcc-debug

也就是说不能用debug,这个会不会影响gdb命令的使用啊?请问怎么解决呢?谢谢。

Avatar_small
依云 说:
2015年2月06日 17:33

@sheao11: 你安装 gcc 的 debug 符号干什么,难道你要调试 gcc 么?

sheao11 说:
2015年2月06日 18:29

ps 敲如下命令后
git config --global core.autocrlf input
显示报错:
error: could not lock config file //.gitconfig: File exists

Avatar_small
輝夜(tadvent) 说:
2015年2月08日 20:15

@sheao11: 是不是装了两个 git,其中一个还没有 config 完又运行了另一个 git config 命令 = =。。。我没有见过这个错误,猜测可能是这样。把 .gitconfig.lock 文件删掉试试看。

sheao11 说:
2015年2月15日 13:54

@輝夜(tadvent): 没有装两个git的。。。

sheao11 说:
2015年2月15日 13:56

@依云: 不是要调试GCC,是要调试程序啊。不安装debug,没有gdb,怎么调试程序啊?

Avatar_small
依云 说:
2015年2月15日 17:05

@sheao11: gdb 应该在叫 gdb 的包里呀。-debug 里应该都是调试符号。不过我现在就不去 Windows 里细看了,你可以 pacman -Ql 包名看看文件列表。

sheao11 说:
2015年2月15日 18:44

@依云: 没有gdb的包啊,不过我单独下了mingw32和mingw64,然后把文件拷到msys的目录下,可以用gdb了,不过肯定是没安装的。

sheao11 说:
2015年2月15日 19:22

@輝夜(tadvent): 哦,可能是我弄错了,那一条已经通过了,只是下面这个:
git config --global mergetool.kdiff3.path "C:/Program Files/KDiff3/kdiff3.exe"

这个路径"C:/Program Files/KDiff3/kdiff3.exe"是什么 意思啊?

sheao11 说:
2015年2月15日 20:35

@輝夜(tadvent): 博主,装gvim前都已经弄好了,可这gvim搞不懂,比如“在 ~/.vim 下新建 bundle 文件夹”—— ~/.vim 是那个目录啊?我没找到

sheao11 说:
2015年2月17日 17:58

博主,不好意思,麻烦您说下
3. 参考 Vundle.vim 的教程设置好 Git 的 Curl 脚本:

https://github.com/gmarik/Vundle.vim/wiki/Vundle-for-Windows

——这个怎么设置啊?

sheao11 说:
2015年2月17日 18:08

安装了gvim,但是并没有看到“可以使 gvim 和 MSYS2 的 vim 共用一套配置文件:~/.vimrc”的这个.vimrc,而且这个文件该如何配置啊?谢谢啦,麻烦您说下

Avatar_small
輝夜(tadvent) 说:
2015年3月02日 01:27

@sheao11: 我可能写的简略了,你是完全没有 Linux 的使用经验吗? ~ 就是前面设的 HOME 目录啊,~/.vim 你就在 ~ 下自己建一个 .vim 目录。 ~/.vimrc 你就在 ~ 下自己建一个 .vimrc 文件额。。。

Avatar_small
輝夜(tadvent) 说:
2015年3月02日 01:37

@sheao11: Curl 的设置,把网页上那段代码复制到 C:\Program Files\Git\cmd\curl.cmd 文件里(假设你的 msysgit 装在 C:\Program Files\Git),开个命令行试一下 curl --version 能不能运行

Avatar_small
kre 说:
2015年4月25日 20:59

博主,有QQ没。。。小白求助。。安装GIT那一步开始一路错误到最后。。。怎么办

Avatar_small
輝夜(tadvent) 说:
2015年4月27日 23:59

@kre: 额。。。具体错误是神马indecision

可以给我发邮件

md51 说:
2015年12月09日 18:04

博主的邮件地址是多少?我第一次弄msys ,一头雾水!希望跟你能多请教!请给出E-mail

Avatar_small
md51 说:
2015年12月09日 19:39

$ pacman -Su
:: 正在进行全面系统更新...
正在解决依赖关系...
正在查找软件包冲突...

软件包 (9) curl-7.45.0-1  flex-2.6.0-1  gcc-libs-4.9.2-6  gmp-6.1.0-1
           grep-2.22-1  libcurl-7.45.0-1  libreadline-6.3.008-6
           mintty-1~2.2.1-1  ncurses-6.0.20151121-1

全部安装大小:  16.11 MiB
净更新大小:  -0.47 MiB

:: 进行安装吗? [Y/n] y
(9/9) 正在检查密钥环里的密钥                       [#####################] 100%
(9/9) 正在检查软件包完整性                         [#####################] 100%
(9/9) 正在加载软件包文件                           [#####################] 100%
(9/9) 正在检查文件冲突                             [#####################] 100%
(9/9) 正在检查可用硬盘空间                         [#####################] 100%
错误:无法打开目录://usr/share/libalpm/hooks/: Permission denied
错误:无法提交处理 (failed to run transaction hooks)
发生错误,没有软件包被更新。
 

 

这是怎么一回事?@辉夜(tadvent)

symphony mobile pric 说:
2018年11月01日 21:28

I will back you website for visit

deep cleaning dubai 说:
2019年9月16日 13:18

Ensuring the most levels in cleanliness and a property is without a doubt our number 1 priority. It is that's why that currently extensive training to cleaners and be sure they only use the safest and the most environmentally hospitable cleaning substances. To last the most beneficial, we go the actual mile so even the littlest corner of your residence is spick and even span. As a result of grease removals to vapor cleaning, being a disinfectant the bogs to washing laundry the outdoor patio rail, the entire thing and alot more are system of the package. The result, our family home deep maintaining services comprise of:

XE88 说:
2021年8月30日 00:11

Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.

Satta king 说:
2021年9月25日 05:21

This is very significant, and yet necessary towards just click this unique backlink:

Junior Certificate R 说:
2022年8月31日 15:35

Dinajpur also one of the best education in the country and the Dinajpur Division also successfully completed the Grade 8 terminal examination tests along with other education boards or divisions of the country, and there are a huge number of students are participated from Dinajpur Board also, Junior Certificate Result Dinajpur Board and all are waiting to check their JSC Result 2022 with full or total marksheet. Both of Junior School Certificate & Junior Dakhil Certificate students are waiting to get official result date to check their total GPA Grade point with subject wise marksheet, the Dinajpur Division also completed those STD-8 final exams in the month of November as per date sheet issued by Bangladesh Secondary and Higher Secondary Education Board and the result is also announced as per the schedule.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter