Compiling SDL_gfx (2.0.17) on Visual Studio 2008 (VS9)

Sadly there are no officially provided binaries for SDL_gfx (unlike most other SDL_* libraries), and so I had to compile it myself. SDL_gfx, however has just about no documentation telling you how to do this - and the methods provided doesn’t even work.

Since it took me a while to get this working, so I thought I’d write it down for future reference.

1. Download and unpack the source package.
2. Rename *.c to *.cpp. This is to solve what seems to be this bug, that supposedly was fixed in VS6.
3. Extract sdlgfx.vcproj from ‘Other Builds\VisualC7.zip’ into the source directory and open it, and go through the Conversion Wizard.
4. Remove the source files from the project, and then add the *.cpp files and the *.h files to the project. This is needed because the paths in the original project file are incorrect.
5. Change target to Release.
6. Add SDL.lib to Linker -> Input -> Additional Dependencies in the project properties.
7. Add BUILD_DLL to C/C++ -> Preprocessor -> Preprocessor Definitions.
8. In SDL_gfxPrimitives, replace

#ifdef WIN32

__inline long int
lrint (double ftl)
{
int intgr;
_asm
{
fld flt
fistp intgr
};
return intgr;
}

#endif

with

#define lrint(x) (floor(x+(x>0) ? 0.5 : -0.5))

(As per this site)
9. Compile, and save the solution somewhere when asked to.
10. There should be 4 compilation errors, all of which can be solved by using static_cast<>():
SDL_rotozoom.cpp (Line 501) becomes:
pc = static_cast<tColorRGBA*>(dst->pixels);
SDL_rotozoom.cpp (Line 657) becomes:
pc = static_cast<tColorY*>(dst->pixels);
SDL_gfxPrimitives.cpp (Line 3105) becomes:
sab = sqrt(static_cast<double>(a2 + b2));
SDL_gfxPrimitives.cpp (Line 4289) becomes:
currentFontdata = static_cast<const unsigned char*>(fontdata);
11. Compile. The project should now compile correctly, and you will find sdlgfx.dll and sdlgfx.lib in the Release sub-folder of your source directory.

Now, this is all good, but I would really prefer either official binaries, *or* fixes to the code problems, and instructions that are actually up to date.

3 Responses to “Compiling SDL_gfx (2.0.17) on Visual Studio 2008 (VS9)


  • Andreas
    July 13th, 2008 01:25
    1

    Thanks for putting this together. I (the maintainer of SDL_gfx) try to incorporate these changes into the next release.

  • n00b Developer · The Fun That Is SDL_gfx (or, how i stopped worrying and learned how to build DLLs)
    August 29th, 2008 11:46
    2

    […] How to Build My SDL_gfx […]

  • FyberOptic
    August 31st, 2008 03:42
    3

    Wow, thanks a lot for this. I wasted so much time today trying to get clanlib to work using SDL + SDL_gfx. That was partially because I started with msys + mingw to build clanlib, but after many hours of frustration only for my test program to still not build properly in the end, I decided to just go to Visual Studio. Everything built just fine (half an hour compared to almost six with mingw), up until SDL_gfx. I was ready to give up completely till I found this page. After your fixes, it compiled like a charm. So thanks again!

Leave a Reply