MSYS2 1: 安裝和環境配置記錄


博客轉自:https://www.cnblogs.com/wswind/p/10650126.html

下載安裝

MSYS2:https://www.msys2.org/

修改鏡像地址

首次安裝后,配置軟件源

sed -i "1iServer = http://mirrors.ustc.edu.cn/msys2/mingw/i686" /etc/pacman.d/mirrorlist.mingw32
sed -i "1iServer = http://mirrors.ustc.edu.cn/msys2/mingw/x86_64" /etc/pacman.d/mirrorlist.mingw64
sed -i "1iServer = http://mirrors.ustc.edu.cn/msys2/msys/$arch" /etc/pacman.d/mirrorlist.msys

更新

pacman -Syu #首次更新要求重啟,重啟后需重新配置軟件源
pacman -Su

配置右鍵菜單

使用WScript是為了解決啟動時窗體閃爍的問題。

創建文件msys2_here.vbs,我放在了 "D:\Pkgs\Tools\msys64_configuration"

set ws=WScript.CreateObject("WScript.shell")
ws.Run "D:\Pkgs\Tools\msys64_configuration\msys2_shell.cmd -mingw32 -here", 0

創建msys2 here.reg ,用於在注冊表中創建菜單。將"D:\Pkgs\Tools\msys64_configuration"改為自己的路徑,雙擊注冊表文件導入即可

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\msys2_shell]
@="MSYS2 Here"
"Icon"="D:\Devs\msys64\msys2.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\msys2_shell\command]
@="WScript \"D:\\Pkgs\\Tools\\msys64_configuration\\msys2_here.vbs\""

參考:
https://zhuanlan.zhihu.com/p/33789023

配置桌面快捷方式

和上一節類似,主要為了解決窗口閃爍問題
新建文件D:\Pkgs\Tools\msys64_configuration\msys2.vbs

set ws=WScript.CreateObject("WScript.shell")
ws.Run "D:\Devs\msys64\msys2_shell.cmd -mingw32", 0

通過右鍵菜單-新建快捷方式,輸入

C:\Windows\System32\wscript.exe "D:\Pkgs\Tools\msys64_configuration\msys2.vbs"

修改快捷方式圖標為

%SystemDrive%\msys64\msys2.ico

訪問windows PATH環境變量

三種方法選擇一個就可以:

  1. msys2_shell.cmd 中取消一行的注釋:set MSYS2_PATH_TYPE=inherit
  2. 調用msys2_shell.cmd時使用-use-full-path參數
  3. 在windows系統的環境變量中添加 MSYS2_PATH_TYPE=inherit

參考:
https://segmentfault.com/q/1010000016064839/a-1020000016068252
https://sourceforge.net/p/msys2/discussion/general/thread/dbe17030/

配置home路徑為windows用戶目錄

/etc/nsswitch.conf

db_home: windows

默認是在/home/%U

參考:
https://superuser.com/questions/809974/msys2-home-folder-show
https://github.com/valtron/llvm-stuff/wiki/Set-up-Windows-dev-environment-with-MSYS2
https://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-mapping-nsswitch

配置clion所需的編譯環境

pacman -S mingw-w64-x86_64-toolchain

# 輸出結果為:

:: 在組 mingw-w64-x86_64-toolchain 中有 17 成員:
:: 軟件倉庫 mingw64
1) mingw-w64-x86_64-binutils 2) mingw-w64-x86_64-crt-git
3) mingw-w64-x86_64-gcc 4) mingw-w64-x86_64-gcc-ada
5) mingw-w64-x86_64-gcc-fortran 6) mingw-w64-x86_64-gcc-libgfortran
7) mingw-w64-x86_64-gcc-libs 8) mingw-w64-x86_64-gcc-objc
9) mingw-w64-x86_64-gdb 10) mingw-w64-x86_64-headers-git
11) mingw-w64-x86_64-libmangle-git 12) mingw-w64-x86_64-libwinpthread-git
13) mingw-w64-x86_64-make 14) mingw-w64-x86_64-pkg-config
15) mingw-w64-x86_64-tools-git 16) mingw-w64-x86_64-winpthreads-git
17) mingw-w64-x86_64-winstorecompat-git

以上都是mingw64的工具鏈配置,如果使用ming32,替換上面的x86_64為i686.

選擇安裝gcc ,gdb ,make的安裝序號即可
參考:
https://blog.csdn.net/weixin_41624493/article/details/80639775
https://blog.csdn.net/imzhujun/article/details/80707635

顯示git branch

不建議使用msys2代替git for windows,實在需要可考慮安裝git for windows sdk代替msys2
在.bashrc或.bash_profile中添加以下內容

function parse_git_branch () {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
  
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOR="\[\033[0m\]"
  
PS1="$GREEN\u@\h$NO_COLOR:\w$YELLOW\$(parse_git_branch)$NO_COLOR\$ "

git for windows ps1:

\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$

參考:
https://gist.github.com/githubteacher/e75edf29d76571f8cc6c


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM