git-bash.exe 和 bash.exe 显示不同的编译器版本和路径

git-bash.exe 和 bash.exe 显示不同的编译器版本和路径

git-bash.exe例如,当我通过选择“Git Bash Here”选项开始并检查我的编译器版本和路径时,我收到以下输出:

$ g++ --version
g++.exe (Rev2, Built by MSYS2 project) 9.2.0
Copyright (C) 2019 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.

$ which g++
/mingw64/bin/g++

但是如果我从 shell 运行,sh.exe即使bash.exe使用--login -i选项,也会得到以下结果:

$ g++ --version
g++ (GCC) 9.1.0
Copyright (C) 2019 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.

$ which g++
/usr/bin/g++

我认为--login -i选项应该加载与相同的环境git-bash.exe

问题

是否可以让它们加载相同的环境?

編輯1

我使用git-sdk-64。它安装在C:\git-sdk-64

git-bash.exe位于C:\git-sdk-64\git-bash.exe

bash.exe并且sh.exe都位于C:\git-sdk-64\usr\bin\

  • C:\git-sdk-64\usr\bin\bash.exe
  • C:\git-sdk-64\usr\bin\sh.exe

我没有cygwin

編輯2

ldd输出g++

$ ldd /usr/bin/g++
        ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7ffea4a50000)
        KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7ffea3ac0000)
        KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7ffea2780000)
        msys-iconv-2.dll => /usr/bin/msys-iconv-2.dll (0x5603f0000)
        msys-2.0.dll => /usr/bin/msys-2.0.dll (0x180040000)
        msys-intl-8.dll => /usr/bin/msys-intl-8.dll (0x17cc50000)

$ ldd /mingw64/bin/g++
        ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7ffea4a50000)
        KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7ffea3ac0000)
        KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7ffea2780000)
        msvcrt.dll => /c/WINDOWS/System32/msvcrt.dll (0x7ffea3ca0000)
        libwinpthread-1.dll => /mingw64/bin/libwinpthread-1.dll (0x64940000)

答案1

它们通常来自不同的环境:第一个是 MSYS,第二个是 Cygwin(我猜)。

它们甚至可能以不同的方式解释目录。Cygwin 具有目录/的同义词C:\cygwin。这使得环境更接近 Unix 系统,但与 MSYS 截然不同。

命令mount可以确认或确认 Cygwin 环境,该命令通常至少声明:

D:/Cygwin on / type ntfs (binary,auto)
C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)
D: on /cygdrive/d type ntfs (binary,posix=0,user,noumount,auto)

Aldd /usr/bin/g++应该显示所使用的 DLL(至少在 Cygwin 上)并指示如何g++编译。

相关内容