Reputation: 2859
I've downloaded SDL library and was able to set the include path without any troubles but setting up the linker is a complete nightmare... How am I suppose to point cmake to correct files?
cmake_minimum_required(VERSION 3.2)
project(simple_timeline_recorder)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build)
set(LIBRARY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/build/")
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/build/")
include_directories("${PROJECT_SOURCE_DIR}/Dependencies/SDL/include")
target_link_libraries(simple_timeline_recorder)
set(SOURCE_FILES src/main.cpp)
add_executable(simple_timeline_recorder ${SOURCE_FILES})
~Thanks for help
edit (vsoftco)>
Unfortunately it does not work for some reason. I'm using CLion from jetbrains with mingw. I've tried with extension and without and I've also tried giving absolute path. No use. The error / exception is the same.
...
include_directories("${PROJECT_SOURCE_DIR}/Dependencies/SDL/include")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -LDependencies/SDL/lib/win32/SDL2")
set(SOURCE_FILES src/main.cpp)
add_executable(simple_timeline_recorder ${SOURCE_FILES})
target_link_libraries(simple_timeline_recorder SDL2)
Error message:
Linking CXX executable simple_timeline_recorder.exe
d:/apps/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lSDL2
collect2.exe: error: ld returned 1 exit status
CMakeFiles\simple_timeline_recorder.dir\build.make:87: recipe for target 'simple_timeline_recorder.exe' failed
CMakeFiles\Makefile2:59: recipe for target 'CMakeFiles/simple_timeline_recorder.dir/all' failed
mingw32-make.exe[2]: *** [simple_timeline_recorder.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles/simple_timeline_recorder.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
Makefile:74: recipe for target 'all' failed
Upvotes: 0
Views: 1434
Reputation: 56547
You didn't seem to have specified the path to the library you want to link against.
Let's say you want to include mylib.so
from /path/to/mylib
. What you can do is adding to your CMakeLists.txt
the line
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/path/to/mylib")
then in the last line of the CMakeLists.txt
(after the ADD_EXECUTABLE
clause) use
TARGET_LINK_LIBRARIES(simple_timeline_recorder mylib)
UPDATED EDIT
Try
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${PROJECT_SOURCE_DIR}/Dependencies/SDL/lib/win32/SDL2")
so you can be sure you get the right path.
Upvotes: 2