1. 头文件指定
1.1 include_directories(path)
包含程序编译所需库的头文件:path——头文件所在目录;
相当于Makefile中使用CFLAGS+=-Ipath;-Ipath,path——头文件所在目录。
编译时,查找优先级高于默认的/usr/include和/usr/local/include;
举例:如针对opencv2编译,添加其头文件为:
include_directories(/path/to/opencv/opencv2/include) include_directories(/path/to/opencv/opencv2/include/opencv)
上述方式也可写为:
set(OpenCV_INCLUDE_DIRS /path/to/opencv/opencv2/include /path/to/opencv/opencv2/include/opencv) include_directories(${OpenCV_INCLUDE_DIRS})
2. 库文件指定
2.1 link_directories(path)
指定程序编译所需要的库路径,path——库文件所在目录;
相当于Makefile中的LDFLAGS += -Lpath,path——库文件所在目录;
也相当于LD_LIBRARY_PATH添加路径的作用;
举例,包含opencv的库路径如下:
link_directories(dirPath1 dirPath2 ...)
2.2 link_libraries(path)
指定需要添加链接库的库文件的路径;注意不是库文件所在目录,而是库文件的路径;
包含Opencv的库文件如下:
link_libraries(/path/to/lib/libopencv_ml.so) link_libraries(/path/to/lib/libopencv_core.so)
也可写为:
set(OpenCV_LIBS /path/to/opencv2/lib/libopencv_ml.so /path/to/opencv2/lib/libopencv_core.so.2.4 /path/to/opencv2/lib/libopencv_imgproc.so) link_libraries(${OpenCV_LIBS})
注:
include ——头文件相关;
link ——库文件相关;
directory ——目录相关;
library ——直接路径相关;