CMake Issue - MinGW and SDL2

Started by
0 comments, last by All8Up 10 years, 6 months ago

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.

Advertisement
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.

This topic is closed to new replies.

Advertisement