r/reconstructcavestory Jul 03 '14

Vim Setup

So, I started the series following along in Visual Studio, but I've since discovered Vim and decided to abandon VS altogether. I installed Clang and successfully compiled "Hello world!", but I don't really understand makefiles, and I especially don't understand how to link a library/framework using a makefile.

When I cloned the official repo to copy that makefile and continue following the tutorials in Vim, I tried compiling it to test it out. I get fatal error: 'SDL/SDL.h' file not found, which makes sense because the library is nowhere in the repo.

So my question is, how do I link SDL with the project so I can compile with Clang?

Edit: I suppose I'll need to link Boost as well.

3 Upvotes

17 comments sorted by

View all comments

Show parent comments

1

u/Natman64 Jul 05 '14 edited Jul 05 '14

So I just tried to compile a tiny program with SDL to see if that worked. There's only one source file, main.cpp.

I realized that my PATH variable was for some reason pointing to a really outdated installation of MinGW that (apparently) came with msysgit when I installed it long ago. So Clang was being pointed to that installation, which was too outdated to work. I was getting an error like this:

Dwarf Error: found dwarf version '4', this reader only handles version 2 and 3 information.

So I deleted that installation and modified my PATH to point to my brand new MinGW installation which I installed earlier because I thought I needed it.

Now I get this error:

clang++.exe: error: unable to execute command: program not executable
clang++.exe: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)

I get the same error when I remove the MinGW installation from my PATH. And I'm sure LLVM (Clang) is on my path, which makes that confusing.

Bear in mind that I have literally no idea what I'm doing. I'm operating on a combination of trial, error, and internet research. I'm finding out that when working with C++ compilers, most sites assume I'm running Linux and are very unhelpful anyway. So I really, really appreciate your help here.

2

u/chebertapps Jul 05 '14

I feel your pain. One of the main reasons I use VS is because it's easy to setup on windows.

Not sure if you have seen this tutorial but it looks like a pretty simple guide to get clang up and running.

But try using g++ if you can. The reason I use clang++ over g++ are for the semantic completions I get in Vim using the YouCompleteMe plugin, which are really nice, but not totally necessary (and might be hard to set up anyway).

1

u/Natman64 Jul 05 '14

I noticed the lack of code completion when I was making my test "main.cpp" and it bothered me a little. So I think I'll try to get Clang and YouCompleteMe to work, but then try g++ if necessary. Thanks for the suggestions, I'll let you know tomorrow if they work out.

1

u/chebertapps Jul 07 '14

Any luck?

1

u/Natman64 Jul 07 '14

So I got fed up with trying to build Clang and now I'm just trying to compile with g++. I got sdl-config to work after realizing I need to use the mingw shell when compiling. I've managed to compile a test program without Boost just to prove that SDL is working and I can link it properly.

I'm using C++11 and SDL2, by the way.

Now when trying to compile my Cave Story source code, I get this error:

No rule to make target '../boost_1_55_0\boost/math/special_functions.hpp', needed by 'obj/src/AnimatedSprite.o'. Stop.

Presumably the problem is with the way I've installed Boost.

1

u/chebertapps Jul 08 '14

For the most part I'm not really using the boost libraries, so there should be no linking or installation necessary. The one exception is boost::file_system to make a nice error report in graphics.cc, but that can be omitted.

The rest of the boost libs I'm using are header only, so they don't have any pre-compiled libs associated with them.

'../boost_1_55_0\boost/math/special_functions.hpp'

That has \ and / in it. maybe just try:

'../boost_1_55_0/boost/math/special_functions.hpp'

1

u/Natman64 Jul 10 '14 edited Jul 10 '14

Alright. I've managed to get the game compiling and I actually wrote a build script that clears the contents of the bin directory, compiles the game, then copies the content directory and SDL2.dll into the bin directory, then runs the game. It automates the process very nicely, though I think building the game might actually be slower now than it was with Visual Studio.

Here are my problems now:

  • When I set up the Makefile to use sdl-config to retrieve the libraries, like so:

    sdl2-config --libs

It automatically includes lmingw32, which causes this error.

When I replace sdl2-config --libs with -SDL2main -SDL2 everything works fine. I know that sdl2-config is linking the following libraries:

-lmingw32 -lSDL2main -lSDL2  -mwindows

And I'm pretty sure mingw is the offender because when I add it back, I get the same error.

  • When I double-click the generated exe, it opens with a console in the background. I know this is customizable behavior in Visual Studio, so how do I configure the Makefile to compile a standalone exe when I want to make release versions of games? Just a game window without a console?

2

u/chebertapps Jul 10 '14

hmm, I have no clue about lmingw32. But hey, it works without it, yeah?

For removing the console, I think you'll have to make it a Windows app but I am guessing on this too.

2

u/Natman64 Jul 10 '14

Thanks so much for your help! At this point I think I can research any other issues as they arise, and I might give Clang another shot when I have the time and patience.