Installing MinGW with Vista

From CodeBlocks

Jump to: navigation, search

--Darthdespotism 07:23, 29 June 2007 (UTC)

Contents

Before we start

Before starting to install MinGW under Windows Vista there are some things to remember:

  • MinGW must be located on the same partition as the files you want to compile
  • There may be issues if you don't install MinGW in the toplevel folder (e.g. C:\MinGW) but in some folder (e.g. C:\Compilers\MinGW). There is a possible solution to this problem (see the "Troubleshooting" section at the bottom of this page).

For this HOWTO I used some Conventions:

  • I assumed you are going to install in C:, if you want to install on another partition (which may be clever as the sources must be on the same partition) you'll have to modifie the path acordingly
  • I used MinGW-Version to indicate that you must use your Version of MinGW here. As you can see on my pictures it is for me 4.2.0 and for those who downloaded on http://mingw.org it is most probably 3.4.2

Just one thing left: I've done this under Vista Business and a friend of mine reported it working with Home Premium. I hope it works on the other versions, too.

Getting MinGW

First of all you need the MinGW Compiler to be installed. I used the installer but all methods desciribed under MinGW installation should work fine. You may althoug want to upgrade your Version of MinGW to 4.* though. When you finished installing the basic MinGW we'll start making it work with Windows Vista. (Note: There is no need to set any %PATH% - variables when you use only Codeblocks, this is the way I'll focuse on)

Actual Setup

Executeables

If you haven't already done it it is time to install and start Code::Blocks. It's a good idea to create a sample "console application" so you have a basic "Hello world" to test your progress. As I first tried to run "Compile" without any Modifications I got the following Error:

-------------- Build: Debug in test ---------------
Compiling: main.cpp
mingw32-g++.exe: CreateProcess: No such file or directory
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings

This doesn't tell us very much. The problem here actually is, that MinGW is unable to find its helper executeables, in this case cc1plus.exe. To fix this go to your "Settings" -> "Compiler and Debugger" -> "Toolchain executeables" -> "Additional paths" and add there the Directory "C:\MinGW\libexec\gcc\mingw32\MinGW-Version where MinGW-Version is the Version of MinGW you are using. If you use a unmodified Version this is most probably 3.4.2, as I have the newer 4.2.0 I use this.

Mingw vista 01.pngMingw vista 02.png

Let's try to compile again and see the progress.

Compiler

Hm still doesn't work, but the error changed:

-------------- Build: Debug in test ---------------
Compiling: main.cpp
C:\Users\Christoph\Projects\test\main.cpp:1:20: error: iostream: No such file or directory
C:\Users\Christoph\Projects\test\main.cpp: In function 'int main()':
C:\Users\Christoph\Projects\test\main.cpp:7: error: 'cout' was not declared in this scope
C:\Users\Christoph\Projects\test\main.cpp:7: error: 'endl' was not declared in this scope
Process terminated with status 1 (0 minutes, 1 seconds)
3 errors, 0 warnings

So MinGW is not able to find <iostream>. Let's tell him where to search:

Still in the Compiler and Debugger dialogue go to "Search directories" -> "Compiler" and add:

C:\MinGW\include\
C:\MinGW\include\c++\MinGW-Version
C:\MinGW\include\c++\MinGW-Version\backward
C:\MinGW\include\c++\MinGW-Version\mingw32
C:\MinGW\lib\gcc\mingw32\MinGW-Version\include

There are not necessarily all of them needed, but these are the directories MinGW searches in normally.

Try again to compile. The compiler should now execute normally, but there is a Linker error left:

Linker

Linking console executable: bin\Debug\test.exe
ld: cannot find -lgcc
Process terminated with status 1 (0 minutes, 1 seconds)
1 errors, 0 warnings

So we apparently need to tell MinGW where to search for it's librarys. This is again done by adding some "Search directories", but now we use the section "Linker"

C:\MinGW\lib\gcc\mingw32\MinGW-Version

Try to compile, it should work.

Mingw vista 03.pngMingw vista 04.png

Trouble shooting

If this does not work out for you there is some advice to figure it out on your own:

  • If there is a file not found by MinGW use your search function to look for it, and add it where it belongs
    • If it's an executeable (.exe) add it to the "additional paths" under "toolchain executeables"
    • If it's a header (.h, .hpp or without extension) add it to "compiler" under "search directories"
    • If it's a library (.o, .a) add it to "linker" under "search directories"
  • Compile with the -v flag. You can do this by simply adding -v to "Build options" -> "Compiler" -> "Other options"
  • Try entering the complete path to each program (for example, changing "mingw32-g++.exe" to "D:\toolkits\MinGW513\bin\mingw32-g++.exe"). This may allow projects to be compiled, regardless of which partition and folder MinGW is installed to. See this forum thread for more details.

An Easy Fix

I have been using this fix that was made available in the Mingw-Users list, by a kind a person. It works fine without having to do any abnormal modifications to your CodeBlocks setups.


If it helps anyone else, I took the three patched drivers that Danny posted (gcc, g++, collect2) and copied them to their various aliases (e.g. c++, mingw-g++, etc) and put them in the appropriate directory structure, and made it a tarball:

http://dessent.net/tmp/gcc-vista-3.4.5-20060117-1.tar.gz

$ tar ztvf gcc-vista-3.4.5-20060117-1.tar.gz -rwxr-xr-x brian/None 86016 2007-05-18 18:41 bin/c++.exe -rwxr-xr-x brian/None 86016 2007-05-18 18:41 bin/g++.exe -rwxr-xr-x brian/None 83456 2007-05-18 18:40 bin/gcc.exe -rwxr-xr-x brian/None 86016 2007-05-18 18:41 bin/mingw32-c++.exe -rwxr-xr-x brian/None 86016 2007-05-18 18:41 bin/mingw32-g++.exe -rwxr-xr-x brian/None 83456 2007-05-18 18:40 bin/mingw32-gcc-3.4.5 -rwxr-xr-x brian/None 83456 2007-05-18 18:40 bin/mingw32-gcc.exe -rwx------ brian/None 85504 2007-05-18 18:41 libexec/gcc/mingw32/3.4.5/collect2.exe

If you unpack this in your MinGW root folder (e.g. /mingw) just like all the other gcc-foo tarballs it should install the files in all the right places. I tested this on a Vista copy running VMware and it worked fine for compiling and linking C and C++.

(That's for 3.4.5 only.)

Personal tools