Compiling in MinGW

I’m trying to set up the source (experimental build) to compile in MinGW on Win 7. Here come the questions:

  1. It looks like there’s a NATIVE=win64 build option in the makefile, but it’s not mentioned in the comments at the top of the file (though win32 is). Is the win64 option functional yet?

  2. I’m following the instructions on the wiki, but there’s no guide to installing the dependencies (SDL2, TTF, and so forth). I’m not sure where to place what. I would use the prepackaged CDDA-deps file if the link weren’t broken and assuming it were up-to-date. Any guidance?

FWIW the RC car mod appears to have used code that breaks MinGW32 compatibility outright: a weird C++2011 thing that folks aren’t supporting. I’m looking into MinGW-w64 (theoretically works on 32bit processors) as a workaround. If it works I’ll post about the process.

A workaround can be found at http://tehsausage.com/mingw-to-string.

Update, 14 September 2012:

All patches here are released in to the public domain, and free for use for any purpose.

Also as stated in an email reply sent to someone regarding gcc bug #52015, this is not a proper MinGW patch. It can break existing programs using the Windows versions of [v]swprintf (as it replaces them with the standard signatures), might(?) cause problems if the functions aren’t inlined, and it is applied to post-build MinGW so it cannot be guaranteed that future libstdc++ changes won’t make enabling this impossible. The patch is also missing a call to __builtin_va_end.

I’m pretty confident I’ve seen that [v]swprintf around in DDA. :-/

Fixed it right up!

Whereas I wasted an afternoon changing to minGW-w64.

Process can be replicated without too much hassle:
0) that link goes to the 32-bit one. I just grabbed the latest 7zip archive, and was going to plug it into Code::Blocks. I’m on WinXP.

  1. Unpack the archive
  2. Open up C::B, go into settings->compiler, make a line for it (Copy and rename), then go to the toolchain tab and change all the files over to their equivalents in the /bin folder you unpacked.
  3. Code::Blocks is gonna want to keep using the previous compiler, though. In order to change that, you have to go to Project->Build options and change the selected compiler. It’ll ask you to do a full rebuild; I did so.

Straightforward in documentation but if you’ve never done it before, really irritating.

KA101 is a firm believer in Evil Overlord Dev Tip #85.

All I’m getting with MinGW is this:

Shifting to Code::Blocks, using this and this as references, I’ve gotten closer.

Trying to compile the Release build (not -SDL or -Localized) gave me an error in file_finder.cpp along the lines of “stat _buff has incomplete type and cannot be defined”. I figured it was, as noted on the wiki, a missing source or header file, so I added everything (including chkjson/chkjson.cpp). The compiler then complained about “json.h” missing, so I replaced it with “…/json.h” since chkjson is in a subdirectory. The result:

||=== Build: Release in Cataclysm (compiler: GNU GCC Compiler) ===| C:\Games\Cataclysm\SRC\src\chkjson\chkjson.cpp||In function 'std::vector<std::basic_string<char> > get_files_from_path(std::string, std::string, bool, bool)':| C:\Games\Cataclysm\SRC\src\chkjson\chkjson.cpp|51|error: aggregate 'get_files_from_path(std::string, std::string, bool, bool)::stat _buff' has incomplete type and cannot be defined| C:\Games\Cataclysm\SRC\src\chkjson\chkjson.cpp|57|error: invalid use of incomplete type 'struct get_files_from_path(std::string, std::string, bool, bool)::stat'| C:\Games\Cataclysm\SRC\src\chkjson\chkjson.cpp|51|error: forward declaration of 'struct get_files_from_path(std::string, std::string, bool, bool)::stat'| ||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 28 second(s)) ===|

I can’t find where “struct stat” is defined. I do see a “struct stats” in player.h, so I think I’ve missed something.

Shifting to MinGW-w64 is probably a good idea, but for the time being we’ll avoid std::to_string()


Removes the offending invocation.

OK. I installed Code::Blocks, set the compiler flags to C++11, forked* & cloned** the repo to my computer, then opened up the CB project file and hit Build. You’ll want to follow the directions in Contributing.md and set yourself up so you can pull updates; that takes some doing but Git’s help is probably good enough. (I think I got through using just that. Needed help learning to reset the thing when Git chokes.)

*Fork=tell Git to create an Anxiety/Cataclysm-DDA setup on their website
**Clone= have Git copy the repo to your computer. May take a WHILE.

I use both the Git for Windows GUI (mostly to delete branches anymore) and the shell. There really isn’t a “git pull upstream master” available in the GUI.

After another failed attempt with C::B, I gave MinGW another go. It turns out I neglected to compile from within MSYS. Derp…

Also, the CDDA-deps link was working, so I dropped those into my MinGW installation as instructed. The only file I already had was IIRC zlib1.dll or thereabouts. I chose not to overwrite it. Even if I should overwrite it, I’m not yet to the point where linker errors might occur, so meh.

Current MinGW issues:

I’m not sure which to run from MSYS: make or mingw32-make. Each has its own set of errors and neither recognizes the -std=c++11 flag (nor -std=c++0x, for what it’s worth). I should have the correct version for mingw32-gcc (“4.8.1 (GCC)”), though gcc returns “3.4.4 (msys special)”. If I comment that flag out, here are the results for each compiler:

make NATIVE=win32 RELEASE=1 TILES=1 SOUND=1 LOCALIZE=0 LUA=0 USE_HOME_DIR=0 DYNAMIC_LINKING=1
This yields a host of errors. I don’t know how to pipe the error log to a file, so I can’t display it properly here. I’m getting stuff along the lines of (copying by hand here:

src/json.h:7:25: unordered_set:  No such file or directory

src/skill.h:8:20: stdint.h: No such file or directory

src/options.h:6:25: unordered_map: No such file or directory

src/name.h:24: error: 'uint32_t' has not been declared
src/name.h:24: error: ISO C++ forbids declaration of 'flags' with no type

src/catacharset.h: In constructor 'utf8_wrapper::utf8_wrapper(const char*)':
src/catacharset.h:52: error: type 'class utf8_wrapper' is not a direct base of 'utf8_wrapper'

mingw32-make NATIVE=win32 RELEASE=1 TILES=1 SOUND=1 LOCALIZE=0 LUA=0 USE_HOME_DIR=0 DYNAMIC_LINKING=1
The results here are mostly the same as above, with some additions along these lines:

src/overmap.cpp:632: error: 'ACTIVE_WORLD_OPTIONS' undeclared (first use this function)

It looks like I’m mostly missing some standard library includes, so there’s a bad path somewhere. I’m not sure how, given I installed MinGW as per the instructions.

I also don’t understand the ACTIVE_WORLD_OPTIONS error, except possibly as a result of the failure to parse/compile options.h correctly due to missing includes.

Is something wrong with my MinGW installation? Am I using the wrong make options (e.g. TILES=1)? Should I just go try Code::Blocks again? I opted to download the source from GitHub as a zip instead of using their application to clone it. Is there some reason their Cataclysm-DDA-master.zip would be missing files?

I don’t know exactly what’s happening, but if you’re compiling with gcc-3.4.4, there’s no way it’s going to work.
To check for that you can modify the makefile to have it invoke gcc -v somewhere.

As I tried to say, I’ve tried MSYS’s GCC 3.4.4 and MinGW’s GCC 4.8.1. Neither recognizes the C++11 flag and both produce roughly the same errors (the latter has a few additions).

I always hate setting up the environment to compile a project like this. Code errors are usually easy to fix. The environment’s usually my biggest problem, with few exceptions. At least I haven’t seen any library issues yet.

The “missing unordered_map” type errors definitely indicate that it’s not able to access the c++11 version of the standard libraries. It HAS to accept --std=c++11 or --std=c++0x now, we will not build without that.

Agreed on environment setup being the most painful part. That’s one of the reasons I’ve pushed back pretty hard on adding external dependencies, and why I put off upgrading to c++11 for a year.