

Just specifying the library filename should work: TARGET_LINK_LIBRARIES(ExecutableName libxxx.a)Īnd TARGET_LINK_LIBRARIES(ExecutableName xxx)Īctually should work too as that would not look for the. This approach is both more flexible when porting your CMake code to other platforms and more easy to debug if something goes wrong than your initial approach. Comment below or reach us via email at or via Twitter at VisualC. We would love to see what you contribute to our repo and are active on reviews and collaboration.

Get rid of your existing link_directories call and add the respective paths as hints to find_library instead. Download the CMake Tools extension for Visual Studio Code and let us know what you think. Note that find_library provides a plethora of options to further specify where to look for the requested library. To link against a library xxx, you would do something like this: find_library(LIB_LOCATION xxx)

This is exactly what find_library does for you. As pointed out in your question, the desired behavior is that you specify just the name of a library and CMake should be able to figure out its location automatically. You obviously would not want to hardcode absolute library paths in your CMakeLists. Imported targets are the most convenient to use, but only if you can get CMake to write the for you. This is usually quite tedious to do manuall, so unless the dependency already provides a config file with an imported target, you probably do not want to go down that road. Since you do not seem to build the dependency as part of the CMake project, the only way to obtain a CMake target to link against, is to create an imported target.
Cmake link library full#
You should always try to give either full paths or CMake targets to target_link_libraries.
