Pergunta

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?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top