Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can use mingw-w64 and MSYS2 with any IDE like eclipse or codeblocks?

  1. I install msys2 with here.

  2. I download i686-5.3.0-release-posix-dwarf-rt_v4-rev0 from here.

  3. after setup msys2-i686-20160205.exe, extract i686-5.3.0-release-posix-dwarf-rt_v4-rev0 in C:\msys32.

  4. finally i run MinGW-w64 Win32 Shell from start menu and run these commands respectively:

    • pacman -Sy pacman

    • pacman -Syu

    • pacman -Su

  5. Add C:\msys32\mingw32\bin in PATH.

my question:

  1. for use mingw-w64 with any IDE, is it true I do?
  2. what difference between MinGW-w64 Win32 Shell and MSYS2 Shell?

Thanks in advance.

like image 436
niksirat Avatar asked May 01 '16 23:05

niksirat


2 Answers

Former msys2 & arch linux user here, currently enrolled in college where the class uses codeblocks as the standard metric for whether a program works or not, and I think I can help you here.

The basic gist is you'd want to install msys2 normally, as well as codeblocks, then use the codeblocks settings to set your compiler to use msys2's mingw-w64 compiler. Confused yet? Its pretty simple overall.

  1. Install codeblocks. Use the installer with mingw already installed, we'll be copying some stuff from the default toolchain later.
  2. Install msys2 (default install location is fine, C:\msys64 for 64 bit and I think C:\msys32 for 32 bit; we'll assume 64 bit for the rest of this guide). Take note of wherever you do install it, we'll need it later.
  3. open the msys2 msys prompt
  4. update msys2 (two part process because windows can't easily swap a file in use out) $ pacman -Syu; it will update a smallish subset of available packages and ask you to close the window.
  5. finish the msys2 update $ pacman -Syu; this time the list will be much larger.
  6. install the base-devel package group $ pacman -Syu base-devel; it will prompt you with a list of packages in the group. You want to skip pacman itself, otherwise it will have the same two-part update thing. Last time I checked this, pacman was number 39 on the list, so you'd put in 1-38,40-56 for what to install (adjust for whatever $currentdate offers you, it may not always be 39).
  7. install a mingw-w64 toolchain pacman -Syu mingw-w64-x86_64-toolchain, it will again prompt you with a choice of packages, you want them all so just hit enter. If you want the 32-bit toolchain you'd use pacman -Syu mingw-w64-i686-toolchain.
  8. Open codeblocks. If this is your first run, it will ask you about file associations and preferences and such. Set those however you like.
  9. In the menu bar, click Settings->Compiler. It should be defaulted to the GNU GCC Compiler. Under that setting there should be a button to copy it. Give the new compiler profile a descriptive name (I went with MSYS2 mingw-w64-x86_64 G++. It will prompt you to update the toolchain executables.
  10. On the compiler screen, there is a tab named Toolchain executables, click it. Set the Compiler's installation directory to wherever you installed msys2 to + either mingw64 for a 64-bit toolchain or mingw32 for a 32-bit toolchain. Assuming default install location and a 64-bit toolchain, this should be C:\msys64\mingw64.
  11. Below this, change the names of all the options under Program Files to remove the mingw32- prefix, except for Make program which must remain mingw32-make.exe. Everything else should have flat names (gcc.exe,g++.exe, etc).
  12. Optional: set this new compiler as the default. You can do this from the same Settings->Compiler window.

I've created a youtube video showing the whole process, since I've not yet seen this documented anywhere on the internet.

like image 200
hanetzer Avatar answered Oct 18 '22 20:10

hanetzer


I too had the question #2: "what difference between MinGW-w64 Win32 Shell and MSYS2 Shell?". I found the answer to it on this official wiki page. For the original complete formatting, please see the original page. Here is the relevant part of the page, as of 9th August of 2017.

MSYS2 susbsystems

MSYS2 consists of three subsystems and their corresponding package repositories, msys2, mingw32, and mingw64.

The mingw subsystems provide native Windows programs and are the main focus of the project. These programs are built to co-operate well with other Windows programs, independently of the other subsystems.

The msys2 subsystem provides an emulated mostly-POSIX-compliant environment for building software, package management, and shell scripting. These programs live in a virtual single-root filesystem (the root is the MSYS2 installation directory). Some effort is made to have the programs work well with native Windows programs, but it's not seamless.

Each of the subsystems provides its own native (i.e. target=host) compiler toolchain, in msys2-devel, mingw-w64-i686-toolchain, and mingw-w64-x86_64-toolchain. There are also cross compiler toolchains with host={i686,x86_64}-pc-msys and target={i686,x86_64}-w64-mingw32 in mingw-w64-cross-toolchain, but these are of limited use because there are no library packages for them.

Shells

Every subsystem has an associated "shell", which is essentially a set of environment variables that allow the subsystems to co-operate properly. These shells can be invoked using launchers in the MSYS2 installation directory or using the shortcuts in the Windows Start menu. The launchers set the MSYSTEM variable and open a terminal window (mintty) with a proper shell (bash). Bash in turn sources /etc/profile which sets the environment depending on the value of MSYSTEM. Without the correct environment, various things may and will (sometimes silently) break. The exception is using mingw subsystems from pure Windows, which shouldn't require any special environment apart from an entry in PATH. Do not set MSYSTEM outside of the shells, because that will also break things.

like image 22
silviubogan Avatar answered Oct 18 '22 19:10

silviubogan