C++11 使用cmake编写makefile

C++11 使用cmake编写makefile,c++11,cmake,C++11,Cmake,我有一个目录结构,如下所示: HP\u检测网 -CMakeLists.txt -包括 -cudaFont.h cudaMappedMemory.h cudaNormalize.h cudaUtility.h -探测网照相机 -包括 -ndetecnet.h -src -Ndetectnet-camera.cpp -CMakeLists.txt 我已将以下代码添加到顶级CMakeLists.txt: cmake_最低要求(2.6版) 项目(HPdetectnet) #版本号。 套装(CMAKE_

我有一个目录结构,如下所示:

HP\u检测网
-CMakeLists.txt
-包括
-cudaFont.h cudaMappedMemory.h cudaNormalize.h cudaUtility.h
-探测网照相机
-包括
-ndetecnet.h
-src
-Ndetectnet-camera.cpp
-CMakeLists.txt
我已将以下代码添加到顶级
CMakeLists.txt

cmake_最低要求(2.6版)
项目(HPdetectnet)
#版本号。
套装(CMAKE_CXX_标准11)
设置(CMAKE_CXX_标志“${CMAKE_CXX_标志}-std=c++1y-Wall”)
设置\目标\属性(检测网\摄像机属性链接器\语言CXX)
#cmake有很多脚本
#用于查找外部库。
#有关更多示例,请参见/usr/local/share/cmake-2.6/Modules/Find*.cmake
查找_包(需要GLUT)
查找_包(需要OpenGL)
目标包含目录(检测网摄像机主/包含)
添加子目录(detectnet\u摄像头)
和下面的代码到
CMakeLists.txt
内部
detectnet摄像头
目录:

cmake_minimum_required(VERSION 2.6)

set_target_properties(detectnet_camera PROPERTIES LINKER_LANGUAGE CXX)

add_executable(detectnet_camera Ndetectnet_camera.cpp)
target_link_libraries(detectnet_camera GLUT OpenGL)
运行“cmake”时,我遇到以下错误:

CMake Error at CMakeLists.txt:3 (set_target_properties):
  set_target_properties Can not find target to add properties to:
  detectnet_camera


-- Configuring incomplete, errors occurred!

有人能告诉我哪里出错了吗?

错误信息很清楚:当调用
set\u target\u properties
时,没有目标
detectnet\u摄像机
-您在之后创建此目标。您应该首先调用
add\u executable(detectnet\u camera Ndetectnet\u camera.cpp)
,然后才调整目标的属性。谢谢,它可以工作……但在此之后,我在子目录的CMakeLists.txt文件中又遇到一个错误。CMake在detectnet\u camera/CMakeLists.txt处出错:7(添加可执行文件):找不到源文件:Ndetectnet\u camera.cpp尝试在添加可执行文件()调用之前将“include\u目录(/home/nidhi/HP\u detectnet)”添加到CMakeLists.txt。命令
包含目录
仅影响头文件的搜索。但是源文件的路径应该在
add\u executable
call中明确指定。由于您的源文件位于
src/
子目录下(相对于
detectnet-camera
目录,您的
CMakeLists.txt
文件所在的目录),您应该将其指定为
src/Ndetectnet\u-camera.cpp
。谢谢。它现在可以工作了。