zoukankan      html  css  js  c++  java
  • 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:PkgsToolsmsys64_configuration"

    set ws=WScript.CreateObject("WScript.shell")
    ws.Run "D:PkgsToolsmsys64_configurationmsys2_shell.cmd -mingw32 -here", 0

    创建msys2 here.reg ,用于在注册表中创建菜单。将"D:PkgsToolsmsys64_configuration"改为自己的路径,双击注册表文件导入即可

    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOTDirectoryBackgroundshellmsys2_shell]
    @="MSYS2 Here"
    "Icon"="D:Devsmsys64msys2.ico"
    
    [HKEY_CLASSES_ROOTDirectoryBackgroundshellmsys2_shellcommand]
    @="WScript "D:\Pkgs\Tools\msys64_configuration\msys2_here.vbs""

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

    配置桌面快捷方式

    和上一节类似,主要为了解决窗口闪烁问题
    新建文件D:PkgsToolsmsys64_configurationmsys2.vbs

    set ws=WScript.CreateObject("WScript.shell")
    ws.Run "D:Devsmsys64msys2_shell.cmd -mingw32", 0

    通过右键菜单-新建快捷方式,输入

    C:WindowsSystem32wscript.exe "D:PkgsToolsmsys64_configurationmsys2.vbs"

    修改快捷方式图标为

    %SystemDrive%msys64msys2.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="[33[0;31m]"
    YELLOW="[33[0;33m]"
    GREEN="[33[0;32m]"
    NO_COLOR="[33[0m]"
      
    PS1="$GREENu@h$NO_COLOR:w$YELLOW$(parse_git_branch)$NO_COLOR$ "

    git for windows ps1:

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

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

  • 相关阅读:
    敏捷软件开发实践-Code Review Process(转)
    随笔1
    随笔
    随笔
    低级错误
    随笔
    随笔2
    随笔
    这以前写的代码
    蛋疼的vs
  • 原文地址:https://www.cnblogs.com/flyinggod/p/12952512.html
Copyright © 2011-2022 走看看