GCC on Windows - Howto

GCC on Windows - Howto

Postby deve » 26 Nov 2014, 10:08

MinGW Howto:

Why gcc instead of Visual Studio on Windows? It is compiler with c++11 support which can be used also in older operating system such as Windows XP or Vista. It is also useful if you prefer gdb debugger or Code Blocks IDE instead of Visual Studio.

Download MinGW installer:
https://sourceforge.net/projects/mingw/ ... t/download

Install it and add path to compiler to your PATH environment variable if it's not already added.
- Run to: My Computer -> Properties -> Advanced system settings -> Environment variables
- Look at system variables and find there PATH variable
- Add there path to compiler. It will look for example: "c:\MinGW\bin;C:\Program Files\CMake\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem"

You can also add there path to cmake for more comfortable work. Note that you cannot have there path to cygwin installation at the same time.

Open c:\mingw\bin directory in terminal and run:
{l Code}: {l Select All Code}
mingw-get update
mingw-get install gcc-g++ gcc-core mingw32-base mingw32-make mingw-utils binutils pthreads pthreads-w32 gmp mpc mpfr libiconv msys-libxml2 zlib


You can also try to use compiler from Code Blocks IDE (but I didn't check it).

Download dependencies from:
http://sourceforge.net/projects/supertu ... p/download
and unpack it to stk-code directory instead of visual studio dependencies.

Source tree should look as follow:
{l Code}: {l Select All Code}
> supertuxkart
>>> stk-assets
>>>>>> karts
>>>>>> tracks
>>>>>> ...
>>> stk-code
>>>>>> build
>>>>>> data
>>>>>> dependencies
>>>>>> src
>>>>>> ...


Open build directory in terminal and use cmake:
{l Code}: {l Select All Code}
cmake .. -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug


Current gcc version has a bug and it crashes (at least for me) during compilation of bullet in release mode. It's because you need to compile it in debug mode. If you have already MinGW configured properly, you can use Clang for release mode compilation ;)

If cmake didn't show any errors, you can use:
{l Code}: {l Select All Code}
mingw32-make


After compilation you need to copy libgcc_s_dw2-1.dll and libstdc++-6.dll libraries from your compiler path to build\bin folder. They are not included in dependencies because they are compiler-specific files. Other files should be already copied to bin directory.

Now you should be able to execute binary:
- open stk-code directory in terminal
- run build\bin\supertuxkart.exe

You can also copy all needed files to one directory. It should have structure as follow:
{l Code}: {l Select All Code}
> supertuxkart
>>> data   (copied from stk-code\data)
>>>>>> gfx
>>>>>> gui
>>>>>> karts   (copied from stk-assets)
>>>>>> tracks   (copied from stk-assets)
>>>>>> ...
>>> supertuxkart.exe   (copied from build\bin)
>>> *.dll   (copied from build\bin)


Make install is not supported atm. (it won't install dll files).

--------------------

To compile application in release mode (to workaround gcc bug) you can use clang. You can download it from there:
http://llvm.org/releases/3.5.0/LLVM-3.5.0-win32.exe

You can simply set following environment variables before run cmake. Run in terminal:
{l Code}: {l Select All Code}
set CC=clang
set CXX=clang++
cmake .. -G "MinGW Makefiles"


Note that in this case you need to have also path to clang in PATH environment variable. You must also use clean build directory to do it. Anyway you need gcc because it is used as a linker and executable depends on libgcc and libstdc++ libraries.
Last edited by deve on 08 Dec 2014, 09:02, edited 2 times in total.
deve
 
Posts: 268
Joined: 23 Jan 2014, 13:45

Re: GCC on Windows - Howto

Postby Auria » 27 Nov 2014, 01:28

Hi, maybe you could post this on our wiki?
Image
User avatar
Auria
STK Moderator
 
Posts: 2976
Joined: 07 Dec 2009, 03:52

Re: GCC on Windows - Howto

Postby konstin » 27 Nov 2014, 15:24

I could make a wiki page of it if you want.

Is theres also a way to get a portable version of the tools? I'ld like to have everything I need for developing on an USB-Stick so I can develop on a windows where I'm not allowed to install software. I already got git + the STK sources + an editor (geany), but neither compiler nor an integration into editor/IDE.
konstin
 
Posts: 37
Joined: 31 May 2014, 20:54

Re: GCC on Windows - Howto

Postby deve » 27 Nov 2014, 18:09

I would prefer to test it first by someone other and maybe add there more information if this will be needed. But yes, post it as wiki page is good idea.

I use geany too ;)

You can copy whole mingw directory to USB if you want. You only need to set PATH environment variable properly. It has about 500 MB, but you can make it a bit smaller when you won't install docs. Also for example libxml2 is probably not needed (I was not sure if irrlicht needs it). If you want I can send you tomorrow script which I use to compile STK on windows.

If you want to have everything portable, then install also gdb (probably "mingw-get install gdb") and copy cmake directory.
deve
 
Posts: 268
Joined: 23 Jan 2014, 13:45

Re: GCC on Windows - Howto

Postby deve » 03 Dec 2014, 11:24

I added few more information to this howto.

@konstin would you try if it works for you?
deve
 
Posts: 268
Joined: 23 Jan 2014, 13:45

Portable development environment

Postby konstin » 04 Dec 2014, 17:35

I tried to do a fully portable version, but I failed because cmake and cmake-gui both didn't work with my portable MinGW (Even changing the %path% variable didn't help - cmake couldn't find it's own binary in the end although it was in %path%). Finally, I installed MinGW on the PC and everything worked fine with portable cmake-gui + Code::Blocks at the first try.

Steps to reproduce the working installation with Code::Blocks:
1 Create a folder on your USB/SD/etc. device, let's name it stk_port
2 Download and Install required software
2.1 cmake (http://www.cmake.org/files/v3.1/cmake-3 ... 32-x86.exe) and install it in stk_port/cmake
2.2 git-bash (http://git-scm.com/download/win not sure if this is the right url tbh) and install it in stk_port/git
2.2 copy stk-code + stk-asset or clone them using git and git-svn, so that there are two new folders stk_port/stk-code and stk_port/stk-assets
2.3 MinGW (https://sourceforge.net/projects/mingw/ ... t/download) install to the system (TODO: installation in stk_port/mingw). Select some extra modules to be installed:
{l Code}: {l Select All Code}
gcc-g++ gcc-core mingw32-base mingw32-make mingw-utils binutils pthreads pthreads-w32 gmp mpc mpfr libiconv msys-libxml2 zlib
This might require some search because they are called differently in the GUI.
2.4 Download dependency package for mingw (http://sourceforge.net/projects/supertu ... p/download) and unpack it into stk_port (so that there is a new folder stk_port/dependecies)
2.5 [Optional] Download and install code::blocks (http://sourceforge.net/projects/codeblo ... -setup.exe) to stk_port/codeblocks
3 cmake
3.1 Open stk_port/cmake/cmake-gui.exe and choose stk_port/stk-code for both source and build folder.
3.2 Press configure and select either "mingw Makefiles" or "Code::blocks - mingw Makefiles" depending your editor choice. If It displays an error because code::blocks executable was not found set the code::blocks path to stk_port/codeblocks/codeblocks.exe . Change install prefix at will. Ignore errors concerning OpenMP.
3.3 Press generate. This will create a new file in stk_port/stk-code you can then use by pressing "open project" and selecting this in code::blocks.
3.4 Press build in Code::blocks

These are not exactly the steps I did because I had to work around some problems, so if something didn't work, please tellme. I'll also check if this works with geany when I have some more spare time because I don't really like code::blocks except for the good integration with cmake.
konstin
 
Posts: 37
Joined: 31 May 2014, 20:54

Re: GCC on Windows - Howto

Postby deve » 04 Dec 2014, 18:29

Really quick reply:

OpenMP doesn't work with mingw embedded in Code Blocks, but it should work with current gcc version (at least works for me when I installed all dependencies). And cmake must work :P Did you set PATH exactly to directory with cmake.exe file? Open terminal and use:
{l Code}: {l Select All Code}
set PATH=%PATH%;c:\Program Files\cmake\bin
cmake.exe --help

Instead of c:\Program Files\cmake\bin write your own path to bin directory. It should be written without quotes.
deve
 
Posts: 268
Joined: 23 Jan 2014, 13:45

Re: GCC on Windows - Howto

Postby deve » 07 Jan 2015, 15:51

I just noticed that it works fine with newer gcc also in release mode (MinGW-w64 fork, can be downloaded here: http://sourceforge.net/projects/mingw-w ... z/download).

Though it needs two changes:
- remove pthread.h from dependencies because it uses different library (libwinpthread-1.dll)
- remove libgomp-1.dll from dependencies because it needs newer version (available in compiler directory)
deve
 
Posts: 268
Joined: 23 Jan 2014, 13:45

Who is online

Users browsing this forum: No registered users and 1 guest