Jump to content
  • Advertisement
Sign in to follow this  

CMake Issue - MinGW and SDL2

This topic is 2097 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!