cmake链接子目录

时间:2015-10-29 13:48:16

标签: c++ cmake qt-creator

我的QT项目中有以下文件夹hieararchy,我需要在ImageProcessing文件夹的类中使用Utility文件夹的某些类。 enter image description here

实用程序的CMAKE文件:

file(GLOB Utilities_Files *.cpp *.h *.hpp)

# add component
add_library(Utilities ${Utilities_Files})

find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(Utilities ${OpenCV_LIBRARIES})

ImageProcessing的CMAKE文件:

file(GLOB ImageProcessing_FILES *.cpp *.h *.hpp)

# add component
add_library(ImageProcessing ${ImageProcessing_FILES})

include_directories(../Utilities)
target_link_libraries(ImageProcessing Utilities)


find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(ImageProcessing ${OpenCV_LIBRARIES})

当我尝试在ImageProcessing类中包含Utilities中的类时:

#include "Utilities/className.h"

编译器总是失败..不确定为什么?似乎有些事情被错过或误解了。

感谢。

1 个答案:

答案 0 :(得分:2)

您的行include_directories(../Utilities)会添加路径../Utilities以包含目录。但是,您在源文件中包含Utilities/className.h,使编译器搜索文件./Utilities/className.h../Utilities/Utilities/className.h

删除Utilitiesinclude_directories中的#include之一。

include_directories(..)

#include "className.h"