Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / Compiling Gosu 2D with MinGw on Windows
- - By sanyaade Date 2011-04-16 20:22
Hello everybody,

I planned to use Gosu with my Students on the BTEC Nationals (A' Level) class. They already using CodeBlocks for the C/C++ Development,
so I wanted to extend the class to cover 2D games in the course using Gosu since it has SDL embedded and abstracted.

Anyway I have try to compile Gosu usin CodeBlocks but with error messages. I have also try it with MinGW from command line which
also fails. I need your help and advice.
My question is:

1.)  --> Is Gosu only tied down to Visual Studio Environment?
2.) ---> Has anybody compile Gosu with either CodeBlocks or with MinGW on Windows? If so please advice me on what to do.

I will be happy if I could get Gosu compile with MinGW on Windows as I love everything I have seen and learned about it.

It will be a joy! Please help!!!

God blesses!!!

Best regards,
Parent - - By jlnr (dev) Date 2011-04-17 05:47
Wow, educational use always makes me feel honored!

Gosu is not intentionally tied down, but I only have time to maintain the Visual C++ projects (not even all possible versions). I take extra care that it works with the free versions though, which I use myself. I think there are tools that convert VC projects to Makefiles, maybe you can try one of these? Gosu is not doing anything exotic really.

(BTW, Gosu does not use SDL :) )
Parent - By sanyaade Date 2011-04-17 23:15

Thank you for your reply. I will search for the tool you mention in your reply --> google it hopefully.

I will get back to you on my outcome and if I need more of your help.

God blesses!!!

Best regards,
Parent - - By seisatsu Date 2011-06-17 08:29
I took a whack at this, but unfortunately, Gosu seems to be using some Windows API calls that have been depreciated since the late 90s. Visual C++ allows it; MinGW does not.

(See: SHGetSpecialFolderPath (added to Windows API with IE 4.0), possibly others.)
Parent - By jlnr (dev) Date 2011-06-17 12:17 Edited 2011-06-17 14:57
Working on it. I would also be happy to include the resulting build files.
Parent - - By jlnr (dev) Date 2011-06-17 14:56
I replaced the superceded SHGetSpecialFolderPath by the deprecated SHGetFolderPath. Can you pull & retry?
Parent - - By erisdiscord Date 2011-06-17 20:21
I'm not an expert on Windows, but shouldn't you be using the non-deprecated, non-superseded SHGetKnownFolderPath instead?
Parent - - By jlnr (dev) Date 2011-06-17 20:58
That one needs Vista, and XP still looks too alive around me (and on my machine, actually) :) - SHGetFolderPath sounds like a pretty safe deprecated function to use too.
Parent - By erisdiscord Date 2011-06-17 21:00
Haha, oops. I kinda missed the compatibility table there. Mistakes happen!
Parent - - By seisatsu Date 2011-06-18 02:40
God you're fast.

I'll pull and retry. There's probably some other nasty landmines hiding in there, so I'll tell you when I hit them.

If I get it to compile I'll give you my MinGW makefile.
Parent - By Maverick Date 2011-06-18 05:11
Jules is the fastest guy in the world. He coined the phrase "in a blink of an eye".
Parent - - By seisatsu Date 2011-06-18 11:08
I added MinGW support and sent the patch to jlnr.
Parent - - By TheOm3ga Date 2011-08-27 13:26
Could you elaborate a bit on the steps to compile using mingw?
Parent - - By jlnr (dev) Date 2011-08-27 14:21
I would guess that it is just a 'make' inside the 'windows' subdirectory - does that generate any errors so far?
Parent - - By TheOm3ga Date 2011-08-27 14:31
It does not seem to be that simple. So far I've been able to create the libgosu.a file. For this, I had to hardcode the path to the DirectX SDK in the Makefile, and also had to download FreeImage, SDL and SDL_Mixer

DXINCLUDE = "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include"

CXXFLAGS += -IFreeImage/Dist -ISDL/include/SDL -ISDL_mixer/include

Now, I'm trying to compile a simple test file, I'm getting lots of undefined references, basically because I don't know which libraries to link against. So far I have this command:
g++ -o programa test.cpp lib/libgosu.a -lopengl32 -lglu32 -LSDL_mixer/lib -lSDL_mixer -LFreeImage/Dist -lfreeimage -LSDL/lib -llibsdl

And the remaining undefined references seem to be related to DirectX or something:

lib/libgosu.a(WindowWin.o): In function windowClass':
c:\gosu/GosuImpl/WindowWin.cpp:163: undefined reference to
lib/libgosu.a(WindowWin.o): In function Window':
c:\gosu/GosuImpl/WindowWin.cpp:239: undefined reference to
c:\gosu/GosuImpl/WindowWin.cpp:241: undefined reference to SetPixelFormat@12'
lib/libgosu.a(WindowWin.o): In function
c:\gosu/GosuImpl/WindowWin.cpp:484: undefined reference to SwapBuffers@4'
lib/libgosu.a(InputWin.o): In function
c:\gosu/GosuImpl/InputWin.cpp:288: undefined reference to IID_IDirectInput8W'
c:\gosu/GosuImpl/InputWin.cpp:288: undefined reference to
c:\gosu/GosuImpl/InputWin.cpp:306: undefined reference to GUID_SysKeyboard'
c:\gosu/GosuImpl/InputWin.cpp:310: undefined reference to
c:\gosu/GosuImpl/InputWin.cpp:324: undefined reference to GUID_SysMouse'
c:\gosu/GosuImpl/InputWin.cpp:328: undefined reference to
lib/libgosu.a(InputWin.o): In function ZN4Gosu5Input4Impl15gamepadCallbackEPK17DIDEVICEINSTANCEWPv@8':
c:\gosu/GosuImpl/InputWin.cpp:120: undefined reference to
lib/libgosu.a(TimingWin.o): In function resetTGT':
c:\gosu/GosuImpl/TimingWin.cpp:14: undefined reference to
lib/libgosu.a(TimingWin.o): In function ZN4Gosu12millisecondsEv':
c:\gosu/GosuImpl/TimingWin.cpp:23: undefined reference to
c:\gosu/GosuImpl/TimingWin.cpp:30: undefined reference to `timeGetTime@0'

I think I'm quite close to do it, but looks like I'm lacking a final library to link.
Parent - - By TheOm3ga Date 2011-08-27 14:42
One more step: adding -lgdi32 resolves the undefined references in WindowWin.cpp. Now only the ones in InputWin and TimingWin remain. Come on! We gotta do it! :D
Parent - - By TheOm3ga Date 2011-08-27 14:59
Finally, looking at the dependences in the VS project file, I managed to wonder what the remaining ones were:
g++ -o programa prueba.cpp -I. lib/libgosu.a -lopengl32 -lglu32 -LSDL_mixer/lib -lSDL_mixer -LFreeImage/Dist -lfreeimage -LSDL/lib -llibsdl -lgdi32 -lwinmm -mwindows -ldxguid -lws2_32 -ldinput8
Parent - - By jlnr (dev) Date 2011-08-27 15:17
Does it work too? I think whatever is required to get it working should be copied into the "Getting Started on Windows" wiki page.
Parent - By TheOm3ga Date 2011-08-27 15:47
So far it works - more or less. I've been able to compile freegemas ( and run it. The main menu and help section works, but the normal gameplay launches a runtime exception, I think it's related to the sound.
Parent - - By TheOm3ga Date 2011-08-27 16:26
Definitely, the sound is broken somewhere when trying to compile with MinGW. Whenever there's a Gosu::Sample, I get this error "This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information".

The rare thing is that, neither the compilation of libgosu nor the compilation of the test.cpp file requested anything related to OpenAL, no include or lib files.
Parent - By jlnr (dev) Date 2011-08-27 16:47
That is weird for sure. I know that Gosu is linked against OpenAL32.lib/OpenAL32.dll in MSVC. It also uses libsndfile.dll, _BUT_ I load that one on demand, for complicated reasons.

Have you put both DLLs next to your .exe? Maybe it's already somehow requiring them.
Parent - - By jlnr (dev) Date 2011-08-27 16:52
Okay, so Seisatsu mentioned on IRC that they are using MSVC for now. I think OpenAL support may simply be missing from the makefile. Maybe it's just a simple fix that you can port over from the MSVC project... :S
Parent - - By TheOm3ga Date 2011-08-27 18:32
YEAAHH I did it! Full fledged compilation, sound included!

I'm gonna try to write an article in the wiki trying to explain all the steps, which are a few.
Parent - By jlnr (dev) Date 2011-08-28 02:51
Thanks, wonderful :) Front page link incoming soon.

BTW, I think you must only be using .ogg files? Because Gosu uses "libsndfile" for all others. I'm going to add it to the wiki.
Parent - By sanyaade Date 2011-08-28 11:01
Hello jnr and TheOm3ga,

Many thanks your efforts on Gosu and for the MinGW port. This is a commendable achievement and brilliant input.

I will be using your steps to try and compile it on my machine and I may be asking for help  :)

I planned to use it in my programming classes from september 2011 -- hope it went well and be ready?

Once again amny thanks!!!

God blesses!!!

Best regards,
Parent - - By RunnerPack Date 2012-12-31 19:26
With a few changes to the makefile and source, I got the library to build using the Ruby Installer Devkit ( Once I get it working fully (including the Ruby wrapper) I'll attempt to update the wiki page.

I can also build the library in MSVC 2010 Express, but (I'm assuming) I need to build it using mingw in order to build the Ruby wrapper, which has to be built with mingw to work with the Ruby Installer binaries (which are built with mingw).

Right now, I'm stuck while trying to build the Ruby wrapper in the Devkit (mingw). I can't figure out, from the MSVC project, what exactly needs compiled/linked along with the generated wrapper code. Do I compile it according to the "Compiling your project" section of the wiki page?

Attempting to compile the wrapper (RubyGosu_wrap.cxx), I get the following:

$ gcc -o RubyGosu_wrap.o RubyGosu_wrap.cxx -I/c/Ruby/include/ruby-1.9.1/ -I.. -I. -I/c/RubyDK/include/
In file included from ../Gosu/Gosu.hpp:13:0,
                 from RubyGosu_wrap.cxx:2267:
RubyGosu_wrap.cxx: In function 'void Gosu::requireFreeImageFor(const char*)':
RubyGosu_wrap.cxx:2329:9: error: expected 'catch' before '__except'
RubyGosu_wrap.cxx:2329:9: error: expected '(' before '__except'
RubyGosu_wrap.cxx:2329:9: error: expected type-specifier before '__except'
RubyGosu_wrap.cxx:2329:18: error: expected ')' before '(' token
RubyGosu_wrap.cxx:2329:18: error: expected '{' before '(' token
RubyGosu_wrap.cxx:2329:37: error: 'GetExceptionCode' was not declared in this scope
RubyGosu_wrap.cxx:2330:9: error: expected ';' before '{' token

I even built my own copy of SWIG in mingw and generated the wrapper again...

Any help will be appreciated. Also, Happy 2013, everyone!
Parent - By jlnr (dev) Date 2013-01-03 07:06 Edited 2013-01-03 07:13
Oh, that is because I use an MSVC-specific feature in that place. __except is a Microsoft extension that MinGW likely doesn't support. Basically, I try to open a DLL file and if a Windows-internal exception is raised, I have a backup plan.


> I need to build it using mingw in order to build the Ruby wrapper, which has to be built with mingw to work with the Ruby Installer binaries (which are built with mingw).

This is correct in theory, but I have always happily used the MinGW Ruby with my MSVC-built Gosu. After all, Gosu is just a DLL file with a single exported C function. I wonder if you might run into trouble with different dynamically linked versions of the C/C++ runtime library though.

I also use the MinGW-built Ruby Installer to test Gosu releases on my machine, so if nothing broke in the last months, you should be able to just use the MSVC-compiled gem.
Up Topic Gosu / Gosu Exchange / Compiling Gosu 2D with MinGw on Windows

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill