9

I downloaded:

https://mingw-w64.org/doku.php/download/mingw-builds

https://mingw-w64.org/doku.php/download/msys2

and installed them under C:/development/msys64. Under this folder I find the msys2.exe and the mingw64 folder, which in turn contains the bin one with all the mingw executable.

I added C:/development/msys64/mingw64/bin folder to the PATH env var. In fact from a Windows prompt I can invoke the gcc - for example. Instead inside the msys2 shell I cannot find them. I mean, they are in /mingw64/bin but they are not available at prompt.

I'm sure I missed some steps!

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
Mark
  • 4,338
  • 7
  • 58
  • 120
  • I "fixed" adding to the local env var PATH `/mingw64/bin` and copying gcc.exe to cc.exe in the same folder. – Mark Jan 16 '17 at 12:14

3 Answers3

15

Method to switch from MinGW-w32 to MinGW-w64

  • Download the executable file of MinGW-w64 Refer the EDIT

(Executable file link may change for future releases, this is for Version 8.1.0, Kindly cross verify the latest version before installing from this link)

  • Installation Process (In Settings):
Version: PICK LATEST
Architecture: x86_64
Threads: posix
Exception: seh

If anyone is trying to add MinGW-w64 as a PATH variable and is not able to find the gdb.exe in C:\msys64\mingw64\bin, try looking for it in the Program files.

C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin

The gdb.exe and other files are located in this directory.


EDIT:

After making some changes in the launch.json file in VSCode, the MinGW-w64 GDB debugger started giving errors because there was 2 versions of MinGW in different folders i.e, MINGW and mingw64!

It is essential that the installation path does not contain any spaces
(i.e., space in "Program Files"), this will create conflicts later.

STEPS:

1. Uninstalled all the versions of GCC that was installed in the PC - Cygwin, MSYS2(32 bit) and mingw64(64 bit) and installed the MinGW-w64 again, this time using the MSYS2.

Please start afresh, if debugger is giving errors and if versions are clashing!

2. Download the MSYS2 installer from this link.

Install process is simple, follow the steps mentioned in the website!

It is essential that the installation path does not contain any spaces. Therefore, we cannot install MinGW-w64 in Program Files.

3. After Installation is complete: Open MSYS2 terminal (pink icon).

Update the package database and base packages using:

pacman -Syu

After this, Update rest of the base packages using:

pacman -Su

4. Now switch over to MSYS2 MinGW 64-bit terminal (blue icon).

To install gcc and g++ for C and C++.

For 64 bit:

pacman -S mingw-w64-x86_64-gcc

To install debugger (gdb).

For 64 bit:

pacman -S mingw-w64-x86_64-gdb

5. Now you're all SET!

Check versions:

gcc --version
g++ --version
gdb --version

6. Finally, remove the old environment variables if any are left and add the new environment variable to the PATH!

BEFORE DEBUGGING FILES IN VSCode, MAKE SURE TO ADD -g tag while building, otherwise breakpoints will be ignored by the debugger!

Footnote: It's very important to keep all the versions in one folder, if folders are different, then life will get tough later!

Vishnu
  • 495
  • 8
  • 14
  • If `gdb.exe` is not in `C:\msys64\mingw64\bin`, it means you forgot to install its package (`mingw-w64-x86_64-gdb`). As the other answer says, mixing MSYS2 with other MinGW distributions usually doesn't end well. – HolyBlackCat Sep 29 '21 at 06:31
  • This worked for me! The other answers did not! When installing from the .exe file, the gdb.exe is created inside the Program Files instead of C:\msys64\mingw64\bin folder. I was looking for it for about an hour, finally found it in the Program Files! Now finally my g++ version is 64 bit after setting it as the PATH variable. I thought it might help someone in the future, that's why I posted it as an answer here. As you said mixing MYSY2 with other MinGW distributions usually doesn't end well. Thanks for your input! I appreciate it! – Vishnu Sep 29 '21 at 07:14
  • In my case, it was because of the **Blue Icon** – Phan Văn Tiến May 19 '23 at 13:41
7

MSYS2 has packages for its own GCC toolchains and you would probably be better off using those toolchains instead of downloading a different one. For example, to use a 64-bit MinGW GCC, you would have to run pacman -S x86_64-w64-mingw32-toolchain and then make sure you are starting MSYS2 using the "MinGW-w64 64-bit Shell" shortcut (or something like that) so that /mingw64/bin is on your PATH.

Also, MSYS2 does not respect your system or user environment variables; it uses its own PATH by default.

David Grayson
  • 84,103
  • 24
  • 152
  • 189
  • 3
    Hi, I ran into the same confusion. I installed MinGW-w64 first and MSYS2 later to find the folder structure in msys installation directory for mingw32 and 64. And then I edited "/etc/fstab" and got msys to find mingw. Is it ok to do so? What do you suppose I shall do? Also, I installed MSYS because make tool wasn't available in MinGW-w64. – Sndn Dec 22 '17 at 07:51
  • 3
    I would not edit fstab, I would use the official MSYS2 toolchains that you can install with pacman unless there is a really good reason to use a different toolchain. – David Grayson Dec 22 '17 at 16:25
-1

the correct path is C:\msys64\ucrt64\bin not C:\msys64\mingw64\bin as given here