我有一个包含源文件的C ++项目。对于外部项目,有一些文件夹需要搜索包含的库:
/home/data/lib/wisenet
/home/data/lib/wise_log
/home/data/lib/wise_rs_device
/home/data/lib/json
/home/data/lib/wise_versioning
我必须写些什么才能在CMake中包含这些外部库?这些文件夹仅包含界面资源(h个文件和.a库)。
我试图像这样包含这些目录:
include_directories(
/home/data/lib/wisenet
/home/data/lib/wise_log
... etc
)
我不理解如何正确添加libwise_rs_device.a
之类的lib文件。
答案 0 :(得分:3)
仅包含目录用于...好吧,包括代码的路径。它不会链接库。
使用外部库的正确方法是使用导入的库:
add_library(wise_rs_device STATIC IMPORTED GLOBAL)
set_target_properties(wise_rs_device PROPERTIES
IMPORTED_LOCATION "path/to/static/library"
INTERFACE_INCLUDE_DIRECTORIES "path/to/headers/of/wise_rs_device"
)
然后,您只需将导入的目标链接到您的目标:
# will link to the static library and add include directories.
target_link_libraries(your_executable PRIVATE wise_rs_device)