simont
simont

Reputation: 72527

CMake, SDL on Mac OS X, "can't find -lSDLmain"

Following the instructions here, I've set up a CMakeLists.txt:

Find_Package (SDL REQUIRED)
Find_Package (SDL_image REQUIRED)

link_libraries (
     ${SDL_LIBRARY}
     ${SDLIMAGE_LIBRARY}
     SDLmain
)

When running cmake, I get the following error:

ld: library not found for -lSDLmain
collect2: error: ld returned 1 exit status
make[2]: *** [src/GameOfLife] Error 1

Running g++ by hand gives the same error:

$ g++-4.7 -std=c++0x ../src/*.cpp -lSDLmain          
ld: library not found for -lSDLmain

How do I fix this?

Upvotes: 1

Views: 1589

Answers (1)

simont
simont

Reputation: 72527

make doesn't know where to find SDLmain; I need to link to the directory using link_directory in `CMakeLists.txt.


Running

$ g++-4.7 -std=c++0x ../src/*.cpp `sdl-config --libs`

works fine, so I've clearly got SDL installed correctly. Checking the output of sdl-config --libs:

$ sdl-config --libs  
-L/opt/local/lib -lSDLmain -lSDL -Wl,-framework,Cocoa

So the thing that's not in the CMakeLists.txt is the -L/opt/local/lib. That should be added into the CMakeLists.txt using link_directory:

link_directories( /opt/local/lib )

And then cmake runs fine.

Upvotes: 2

Related Questions