MantisBT - CMake
View Issue Details
0013769CMakeModulespublic2012-12-02 03:532013-05-06 09:32
R Cullen 
Benjamin Eikel 
normalmajoralways
closedfixed 
MinGWWindows7
CMake 2.8.10.1 
 
0013769: FindSDL.cmake libraries in wrong order
The FindSDL.cmake file does not order the SDL libraries correctly. "-lSDLmain" must be added to the g++ arguments before "-lSDL", not doing this results in linking errors like those below :

c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/lib\libSDLmain.a(SDL_win32_main.o): In function `redirect_output':
/Users/slouken/release/SDL/SDL-1.2.15/./src/main/win32/SDL_win32_main.c:219: undefined reference to `SDL_strlcpy'
/Users/slouken/release/SDL/SDL-1.2.15/./src/main/win32/SDL_win32_main.c:220: undefined reference to `SDL_strlcat'
...
Install MinGW
Compile SDL using MinGW
Compile attached program using :
cmake -Wdev -DSDL_BUILDING_LIBRARY=FALSE -G"MSYS Makefiles" .. && make VERBOSE=1
Here are the sources if you dont trust the .zip

test.cpp
#include "SDL.h"

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define SCREEN_DEPTH 8

int main(int argc, char *argv[]) {
     SDL_Surface *screen;
     Uint8 *p;
     int x = 10;
     int y = 20;
     
     SDL_Init(SDL_INIT_VIDEO);

     screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);
     
     p = (Uint8 *)screen->pixels + y * screen->pitch + x * screen->format->BytesPerPixel;
     *p=0xf0;

     SDL_Flip(screen);
     while(1);
}

CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
project(MyProject)

set(EXECUTABLE_NAME "sdl_bug")

#SET THIS TO YOUR MING INSTALATION
if( WIN32 )
    set(CMAKE_PREFIX_PATH "c:/MinGW/")
endif()

add_executable(${EXECUTABLE_NAME} test.cpp)

find_package(SDL REQUIRED)
if(SDL_FOUND)
    include_directories(${SDL_INCLUDE_DIR})
    target_link_libraries(${EXECUTABLE_NAME} ${SDL_LIBRARY})
endif()
No tags attached.
zip sources.zip (898) 2012-12-02 03:53
https://public.kitware.com/Bug/file/4580/sources.zip
Issue History
2012-12-02 03:53R CullenNew Issue
2012-12-02 03:53R CullenFile Added: sources.zip
2012-12-02 07:53Benjamin EikelNote Added: 0031795
2012-12-02 08:38Benjamin EikelNote Added: 0031796
2012-12-31 11:20Benjamin EikelStatusnew => resolved
2012-12-31 11:20Benjamin EikelResolutionopen => fixed
2012-12-31 11:20Benjamin EikelAssigned To => Benjamin Eikel
2013-05-06 09:32Robert MaynardNote Added: 0032995
2013-05-06 09:32Robert MaynardStatusresolved => closed

Notes
(0031795)
Benjamin Eikel   
2012-12-02 07:53   
I tried it and I can reproduce your problem. The problem is gone if I link against "bin/SDL.dll" instead of "lib/libSDL.dll.a", or if I change the order of "libSDL.dll.a" and "libSDLmain.a", as you suggested.
(0031796)
Benjamin Eikel   
2012-12-02 08:38   
I pushed a possible fix (http://cmake.org/gitweb?p=stage/cmake.git;a=commit;h=981629f701c598f58115445456ee733077beae8d [^]) to the CMake topic stage.
I have tested the change on Windows, where it fixed the problem described in this bug, and on Linux, where it did not produce any new bugs. I have not tested it on OS X.
(0032995)
Robert Maynard   
2013-05-06 09:32   
Closing resolved issues that have not been updated in more than 4 months.