Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Getting (& Keeping) libgosu & C++ Games Compiling in MSYS2
- - By RunnerPack Date 2016-03-19 01:51
I've been trying to compile a (C++) Gosu program under MSYS2. I'm following the (out-of-date) "Compiling on Mingw" tutorial (https://github.com/gosu/gosu/wiki/Compiling-in-Windows-using-MinGW).

Surprisingly (given my lack of experience in these things) I was able to modify the instructions enough to build libgosu.a itself (with only a few compiler warnings). I've been attempting to compile the "Tutorial.cpp" that comes with Gosu, and I'm stuck.

I've made my own Makefile. When I run it, I get a lot of "undefined references" as you can see: http://pastebin.com/PUNVMWJg
The compiler also seems to freeze, because I have to press Ctrl+C to get back to a prompt. (Although, I suppose this could be a bug in MSYS2...)
If I comment out "-std=c++11", I get this: http://pastebin.com/QXB2X7HV
Either way, I don't get a nice Tutorial.exe to run.

My hope is that the collective experience of the smart people here can help me get this working, and then we can use this thread to deal with new issues that crop up as the various bits and bobs Gosu relies on are modified (as they invariably and incessantly are) by their respective maintainers.

I love developing with Gosu in Ruby, but I would really like to (someday) build actual games that others might want to play, and distributing Ruby+Gosu games is too troublesome. The performance boost of C++ is another nice perk...

Thanks for reading!
Parent - - By jlnr (dev) Date 2016-03-19 19:58
Is it maybe as simple as passing -lstdc++ to the linker? It looks like it can't find anything from the standard library :)

If C++11 is a problem, you can retry with the last C++98 version of Tutorial.cpp:

https://github.com/gosu/gosu/commit/7c00e01f03cc88ae67248a824e2a4b5da79b9977
Parent - - By RunnerPack Date 2016-03-19 20:39 Edited 2016-03-19 23:28
That got us much closer! I knew it would be something n00bish like that -_-''

Here's the output after adding that: http://pastebin.com/cPqw9ZZR

Looks like problems with pthreads and Vorbis. I think I can go from here, but as usual, any advice is appreciated.

EDIT: adding "-lpthread" didn't help... still looking :)

EDIT2: A problem with the Makefile was keeping stb_vorbis.c from being built and included in libgosu.a. The pthread thing is still eluding me, though :/
Parent - - By jlnr (dev) Date 2016-03-20 00:02
Ah right, the MinGW Makefile precedes the switch from libogg/libvorbis to stb_vorbis.c. We should probably fix this in master too.

The only thing I found about the pthread error is this: https://github.com/rust-lang/rust/issues/29649

But I'm not sure how that translates to your setup.
Parent - - By RunnerPack Date 2016-03-20 01:17
Ah right, the MinGW Makefile precedes the switch from libogg/libvorbis to stb_vorbis.c. We should probably fix this in master too.

Does that also mean I don't need the three Ogg/Vorbis .DLLs when I distribute my games?

BTW, I couldn't get it to work just including stb_vorbis.c (something about certain things being declared static it didn't like *shrug*), but I renamed it to .cpp, and that seemed to work, so... *shrug*

The only thing I found about the pthread error is this: https://github.com/rust-lang/rust/issues/29649

But I'm not sure how that translates to your setup.


Yeah, I found that, too. I'm as unsure as you are about its usefulness... I think I'm going to have to contact the MSYS2 maintainers.

It looks like I have all the (32-bit) thread-related "packages" installed:
$ pacman -Ss | grep '^\w.*hread'
mingw32/mingw-w64-i686-libwinpthread-git 5.0.0.4573.628fdbf-1 (mingw-w64-i686-toolchain) [installed]
mingw32/mingw-w64-i686-winpthreads-git 5.0.0.4573.628fdbf-1 (mingw-w64-i686-toolchain) [installed]
mingw64/mingw-w64-x86_64-libwinpthread-git 5.0.0.4573.628fdbf-1 (mingw-w64-x86_64-toolchain)
mingw64/mingw-w64-x86_64-winpthreads-git 5.0.0.4573.628fdbf-1 (mingw-w64-x86_64-toolchain)
msys/mingw-w64-cross-winpthreads-git 5.0.0.4574.ce1ad45-1 (mingw-w64-cross-toolchain mingw-w64-cross)


I might try to install the 64-bit ones and recompile everything 64-bit, just to see if they're more complete/compatible.
Parent - By jlnr (dev) Date 2016-03-20 15:17

> Does that also mean I don't need the three Ogg/Vorbis .DLLs when I distribute my games?


Yep! Gosu still needs libsndfile.dll, though.
Parent - - By RunnerPack Date 2016-03-24 02:55
The only thing I found about the pthread error is this: https://github.com/rust-lang/rust/issues/29649

It turns out, this thread was the key! Specifically, this post, which mentions another MinGW installer, and a specific build of MinGW that uses win32 threads.

I installed it, copied the mingw32 folder it created into my main MSYS2 folder (after renaming the existing one, just in case), ran make, found out CC=cc, copied gcc.exe to cc.exe, ran make again, and got a working Tutorial.exe that has a space-ship you can fly around and stars that make noises! Woot! :D

Next step is to try to use just that second installer and do another pair of makefiles that allows one to run make (or possibly mingw32-make) from a standard Windows Cmd shell and end up with a libgosu.a and a Whatever.exe. Then, I can write that up in the relevant section of the wiki, and wait for someone to "improve" something until it breaks again :P
Parent - - By jlnr (dev) Date 2016-03-24 19:45
Sweet! :) Thanks for digging into this. I think putting the whole Makefile into the wiki wouldn't be such a bad idea - it makes it even easier to contribute to it.
Parent - By RunnerPack Date 2016-03-25 00:03
I would do that, but I had to do so much more than just editing the makefile that I don't think it would be much of an improvement on what is already there (plus, I might have included superfluous things). Also, like I alluded to in my previous post, I don't think the full MSYS2 distribution is necessary to make this work. I believe all one needs are the Mingw native compiler tools and the requisite libraries, but I still have to prove that.
Parent - - By RunnerPack Date 2016-03-27 15:48
A quick question to anyone familiar with using gcc under windows: What argument(s) do you pass to gcc to prevent the "DOS" (console) window from popping up along with the Gosu-generated window? I used to know this, and I even tried searching both the forums and the 'Net at large, to no avail...
Parent - - By jlnr (dev) Date 2016-03-27 18:29
I remembered that it is "/subsystem:console" in the Visual C++ compiler, and that brought up this result: http://stackoverflow.com/questions/7474504/compiling-a-win32-gui-app-without-a-console-using-mingw-and-eclipse
Parent - - By RunnerPack Date 2016-03-27 19:35
Thanks again, jlnr! Adding -mwindows to LDFLAGS did the trick!

BTW, I've uninstalled MSYS2. With just the stand-alone Mingw installer, and with its /bin folder on the path (which is easily done by running the batch file it comes with), I am able to use mingw32-make at a normal Cmd prompt to build the Tutorial program :D

I had to modify the paths in the makefile, but other than that it "Just Worked(tm)" ;)

Now I need to modify the other makefile accordingly and see if I can still build Gosu itself. Once that works, I'll be able to update the wiki page :D
Parent - - By jlnr (dev) Date 2016-03-27 21:39
Awesome, congrats on the working build :)
Parent - - By RunnerPack Date 2016-04-04 00:56
Thanks! I have a couple of questions about things I came across while updating the wiki guide:
1. Is the DirectX SDK needed when compiling Gosu? If so, why?
I found the following in the linker section of the VC project file: SDL2.lib, opengl32.lib, openal32.lib, winmm.lib, delayimp.lib (Note: DirectX stuff conspicuously absent...)
Mingw doesn't even include a delayimp (although it does have a delayimp.h), but libgosu.a seems to compile and work fine without it.
2. What libraries are needed when building programs based on Gosu?
I experimented and found that some of the libraries suggested by the current guide don't appear to be necessary, including some seemingly DirectX-related libraries distributed with MinGW (e.g. libdxguid.a and libdinput8.a). The bare minimum seems to be: gosu, stdc++, libpthread (or whatever's linked when you pass the -pthread option), SDL2, OpenAl32, opengl32, glu32, and winmm
It would be great if there was an up-to-date (per platform?) list of every library needed for both Gosu itself and Gosu apps. Something to add to the wiki, maybe?
Parent - - By jlnr (dev) Date 2016-04-04 09:37
1. The DirectX SDK used to be required up until Gosu 0.8.0. Now this is all handled by SDL2.lib, which wraps this for us.

delayimp.lib is MSVC-specific and does not really matter.

2. I'm curious about glu32, does it break if you omit this library? Gosu doesn't really use it.

I think you forgot libsndfile in your list, but otherwise it looks fine.

> It would be great if there was an up-to-date (per platform?) list of every library needed for both Gosu itself and Gosu apps. Something to add to the wiki, maybe?


I think the list of dev dependencies can live on the Wiki page for the respective platform, as with GettingStartedOnLinux. If you compile Gosu with MSVC, gosu.git includes all the required .lib files (SDL2, OpenAL, libsndfile), so this only applies to Compiling-in-Windows-using-MinGW. (Which should probably be renamed to be more in line with the other GettingStartedOn... pages)

Not sure where to list the runtime dependencies. Does the MSYS/MinGW build need libraries at runtime that the MSVC build doesn't? Are pthread and stdc++ statically linked?
Parent - - By RunnerPack Date 2016-04-11 22:30
1. Good to know that after all the trouble I went through to install it :P
2. You're right; glu32 isn't needed to compile Tutorial.cpp. It could be useful to someone doing custom GL stuff along with Gosu, but I'll probably leave it out to keep from confusing noobs. I wasn't including it in Gosu itself, BTW.
My post contains two lists. Which one needs libsndfile? It's currently in the Gosu makefile, but not the Tutorial one. Is it supposed to be the other way around? If not, how is it being linked by VC, since it isn't in the VC project? Is "AutoLink.hpp" doing it?
Does the MSYS/MinGW build need libraries at runtime that the MSVC build doesn't?
Yes. It requires libstdc++-6.dll.
Are pthread and stdc++ statically linked?
I think pthread is, but stdc++ isn't (see answer above). I should probably figure out how to ensure they're both static, to cut down on the DLLs required.
What if we made a "Getting Started on Windows" page that linked to separate MSVC and Mingw pages?
Parent - By jlnr (dev) Date 2016-04-18 18:45

> My post contains two lists. Which one needs libsndfile?


To be honest, I'm not even sure. It seems that only Gosu itself should need it. Sometimes linking a game requires a dependency .lib though, and I haven't taken the time to work out why. I usually go with trial & error, like a pro. :/ So, if everything builds and sound works, then don't worry.

> What if we made a "Getting Started on Windows" page that linked to separate MSVC and Mingw pages?


Sounds good! Can you create new wiki pages as a non-org member? If not, I can simply make you a member.

One thing that worries me a little is the amount of Linux distros, Ruby versions, C++ compilers etc. Gosu is built with. But I've already opened a gazillion tabs in the background to sign up for free CI services. It seems like this will be an evening well spent. If I understand things right, Appveyor even lets you automate MinGW builds (for free!), which would make me feel much better about having a MinGW Makefile in Gosu's git repository proper. But first I'll set up Travis for Linux builds.
Parent - By IgorJorobus Date 2016-10-07 06:17
Hi guys. I Just want to share my interest on this matter, when possible I try to avoid Microsoft products (may exist a contradiction, I use Windows, but I try to keep away from Visual Studio or related IDEs/products). So MinGW fan here, a new one, since I've been using Gosu from Ruby but getting my head into C++ nowadays.

Could we have at some point a well document and updated wiki page explaining how to setup the environment to develop C++ games with Gosu? Even better, we could have a... repository with all the dependencies needed, to have them quickly on our PC, of course those heavy libraries (if any) will not be there, but we can provide the link to download it. If someone could create the page, I could be in charge of the repository creation. What do you think? I still don't have experience in C++, I had made some C developments for embedded software but still not very experienced in C++ library matters, so I got a bit confused reading the whole post. Best regards.
Up Topic Gosu / Gosu Exchange / Getting (& Keeping) libgosu & C++ Games Compiling in MSYS2

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill