Issue
This Content is from Stack Overflow. Question asked by Bmk95
I am trying to use target_link_libraries in a project on clion, but when i run the project the following error is printed:
/usr/bin/ld: cannot find -lctop_common
/usr/bin/ld: cannot find -lctop_log
/usr/bin/ld: cannot find -lctop_util
/usr/bin/ld: cannot find -leigen
/usr/bin/ld: cannot find -lcrl
/usr/bin/ld: cannot find -lcrl-algorithm
/usr/bin/ld: cannot find -lcrl-loader
/usr/bin/ld: cannot find -lcrl-tsplib
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
This is what my cmakelist file includes:
cmake_minimum_required(VERSION 2.8.3)
project(planner_standalone_grasp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-diagnostics-color")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
# find all cpp files in currect directory (where CMakeLists.txt is)
file(GLOB SOURCE_FILES FILES_MATCHING PATTERN "./src/*.cpp")
include_directories(src)
add_executable(${PROJECT_NAME} main.cpp ${SOURCE_FILES})
set(EXE_LIBS
ctop_common
ctop_log
ctop_util
eigen
crl
crl-algorithm
crl-loader
crl-tsplib
yaml-cpp
)
target_link_libraries(${PROJECT_NAME} ${EXE_LIBS})
… Any help would be highly appreciated.
Solution
target_link_libraries tells cmake what libraries to link against (the -l flag that is). You have to specify where to find said libraries too! this can be done with target_link_directories… (the -L flag).
If you have these libraries in the lib folder, make sure they are compiled for the same platform as the executable you are trying to build.
I believe on linux you can also drop the libraries in the lib folder and not use the target_link_directories inc make, not sure…
so:
target_link_libraries specifies the names of the libraries,
target_link_directories specifies the directories of these libraries.
This Question was asked in StackOverflow by Bmk95 and Answered by Plegeus It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.