Jump to content
  • Advertisement
Sign in to follow this  
deathreaper945

CMake Issue - MinGW and SDL2

This topic is 1731 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
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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!