Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

CMake Issue - MinGW and SDL2

4: Adsense
  • You cannot reply to this topic
1 reply to this topic

#1 Zoids   Members   


Posted 22 October 2013 - 12:07 PM

Hello everyone,


I have been struggling with an issue the past few days (since Saturday really) with CMake and MinGW/SDL2. First of all, I'm already experienced with MinGW and making Makfiles for it. However, I am not experienced with CMake thus why I wanted to learn to use it. I've made a quick test project using SDL2 to experiment with CMake. CMake seems to build just perfectly but I will run into issue of linking SDL.


The errors is undefined references to SDL_Init and SDL_Quit (which obviously means it's not being link). The strange thing, -lSDL2main and -lSDL2 is being used. I have three pictures for you to refer: http://imgur.com/a/j2qbH. Additionally, I was using this quick 'tutorial' - http://duganchen.ca/building-sdl2-programs-with-cmake-and-pkgconfig/ although I had to adjust some things to make it work.


Useful information:

  • Windows 8
  • MinGW
  • Using PkgConfig to find SDL2 (I have not had much success with FindSDL2.cmake for some reason)
  • Placed SDL2 in their respective folders of MinGW (bin, include, lib)

Thank you for your time.


P.S. I apologize if this wasn't the right subforum to ask this kind of question.

Edited by deathreaper945, 22 October 2013 - 12:10 PM.

#2 AllEightUp   Moderators   


Posted 23 October 2013 - 07:25 AM

So the problem does not seem to be in your usage of CMake at all given the supplied information. The problem is in the fact that you compiled the main as a 'cpp' file instead of a 'c' and ming is attempting to link to the wrong function names. (This is the most likely case from the information you posted, could still be wrong.) Anyway, make the following change:

#include "SDL.h"
Wrap it with:

extern "C"
#include "SDL.h"
Basically this simply tells the compiler that all the names in SDL.h are C style name and linkage so when referenced from 'main.cpp' they will later resolve correctly.

Hope this fixes things for you.