Building SDL2_gfx for Codeblocks/mingw

Hello everyone,

sorry if this is not the right section where to post this request.
I have aproblem building SDL2_gfx (http://www.ferzkopp.net/wordpress/2016/01/02/sdl_gfx-sdl2_gfx/) for mingw/codeblocks.

I compiled the SDL2_gfx library, but i was unable to use it

I get many undefined references

Here are just two:

…\TDM-GCC-64\lib\libSdl_Gfx.a(SDL2_gfxPrimitives.o):SDL2_gfxPrimitives.c|| undefined reference to SDL_SetRenderDrawBlendMode'| ..\..\TDM-GCC-64\lib\libSdl_Gfx.a(SDL2_gfxPrimitives.o):SDL2_gfxPrimitives.c|| undefined reference toSDL_RenderDrawPoint’|

and many others…

Could someone help me in this?
Are you linking the SDL2 library? I'm asking because SDL_SetRenderDrawBlendMode and SDL_RenderDrawPoint are part of the core SDL2 library.
Last edited on
Thank you for the reply.

Yes, i'm linking SDL2main and SDL2.

Well, the linker is complaining that it can't find those functions in the libraries it's checking.

So you've either not told the linker which libraries to link against, or you're doing it in a bad order. Link against those after linking against your own object files.
I added the library to link against in the following order

SDL2main
SDL2
sdl_gfx

build log errors:

I:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libsdl_gfx.a(SDL2_gfxPrimitives.o):SDL2_gfxPrimitives.c:(.text+0x5e): undefined reference to `SDL_SetRenderDrawBlendMode'
I:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libsdl_gfx.a(SDL2_gfxPrimitives.o):SDL2_gfxPrimitives.c:(.text+0x8d): undefined reference to `SDL_RenderDrawPoint'
I:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../lib/libsdl_gfx.a(SDL2_gfxPrimitives.o):SDL2_gfxPrimitives.c:(.text+0x167): undefined reference to `SDL_RenderDrawLine'
Last edited on
Does it work if you put sdl_gfx first?
Last edited on
No, it doesn't work.

I thought this was a problem related to mingw 32 or 64 bit version.
I checked and seems that the library is 32. Deleted all the 64 bit versions.

I first builded the SDL2_GFX library. The SDL2_GFX links against

SDL2main
SDL2

This produces a library in the bin/release (libSdl_Gfx.a).

Then i copy the libSdl_Gfx.a in the "TDM-GCC-64\x86_64-w64-mingw32\lib"

The test program of the library produces the error:

||=== Build: Release in SDLGFXTest (compiler: GNU GCC Compiler) ===|
obj\Release\testgfx.o:testgfx.c|| undefined reference to `SDLTest_CommonCreateState'|
obj\Release\testgfx.o:testgfx.c|| undefined reference to `SDLTest_CommonArg'|
obj\Release\testgfx.o:testgfx.c|| undefined reference to `SDLTest_CommonInit'|
obj\Release\testgfx.o:testgfx.c|| undefined reference to `SDLTest_CommonEvent'|
obj\Release\testgfx.o:testgfx.c|| undefined reference to `SDLTest_CommonUsage'|
obj\Release\testgfx.o:testgfx.c|| undefined reference to `SDLTest_CommonQuit'|
I:\TDM-GCC-64\bin\..\lib\gcc\x86_64-w64-mingw32\5.1.0\..\..\..\..\x86_64-w64-mingw32\lib\..\lib\libmingw32.a(lib64_libmingw32_a-crt0_c.o)||In function `main':|
C:\crossdev\src\mingw-w64-v4-git\mingw-w64-crt\crt\crt0_c.c|18|undefined reference to `WinMain'|
||error: ld returned 1 exit status|
||=== Build failed: 8 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|


Last edited on
I don't know an exact solution to your linking problems (you're either not looking in the right place, or you're putting something in the wrong place).

But it might help others on the forum if you add --verbose to your command line when you compile, and paste the output.

I personally avoid copying around .a files, I find it to be a mess once you start working with multiple libraries. On my Windows machine, I have a folder either called "C:\libs" or "C:\libraries" and I have a subfolder for each library (ex: C:\libs\fftw-3.3.7) that I download and build. I add that project's include and lib path to g++. This makes it easier to keep track of which libraries you have, and makes updating them easier.
Last edited on
Thank you for the reply.

I tried in Ubuntu and everything works flawlessy.

Don't know if there is something specific i should use on mingw / codeblocks

Btw, i rebuilt latest version of the library (1.04) and added the location of the SDL2 library includes.

The test program now shos this error:

||=== Build: Release in SDLGFXTest (compiler: GNU GCC Compiler) ===|
I:\TDM-GCC-64\bin\..\lib\gcc\x86_64-w64-mingw32\5.1.0\..\..\..\..\x86_64-w64-mingw32\lib\..\lib\libmingw32.a(lib64_libmingw32_a-crt0_c.o)||In function `main':|
C:\crossdev\src\mingw-w64-v4-git\mingw-w64-crt\crt\crt0_c.c|18|undefined reference to `WinMain'|
Last edited on
Topic archived. No new replies allowed.