Reputation: 261
What is the equivalent to -l
as a gcc
directive for ld
to link to a library in cmake?
For example, g++ main.cpp -o myProgram -L./lib -lmyLib
, but for cmake?
Upvotes: 2
Views: 1352
Reputation: 54737
The function you are looking for is target_link_libraries
.
Your command line translates to the following CMake file:
project(myCMakeProject)
cmake_minimum_required(VERSION 2.8)
link_directories(./lib)
add_executable(myProgram main.cpp)
target_link_libraries(myProgram myLib)
Note that in CMake it is unusual to hardcode link directories. Consider using find_library
or a generated config file providing an imported target instead.
Upvotes: 6