一、下载插件
装好CMake和CMake tools之后,vscode下方会有Build和CMake【Debug】
二、项目目录
settings.json文件中加入cmake的path
{
"clang.cflags":[
"-I${workspaceRoot}/include"
],
"python.pythonPath": "D:\\AppData\\anaconda3\\python.exe",
"C_Cpp.updateChannel": "Insiders",
"cmake.configureOnOpen": true,
"explorer.confirmDelete": false,
"cmake.cmakePath": "D:\\AppC++\\cmake-3.9.0\\bin\\cmake.exe"
}
三、编写CMakeLists.txt
CMakeLists.txt文件
# 最低CMake版本要求
cmake_minimum_required(VERSION 3.9.0)
# 项目名称,编译好dll或exe的名称
project(XCDNN)
# 设置C/C++标准
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 头文件路径
include_directories("include" "D:\\AppC++\\opencv-4.1.2\\opencv\\build\\x64\\MinGW\\install\\include")
include_directories("include" "D:\\AppC++\\package_c++")
include_directories("include" "./3rd")
# 枚举头文件
file(GLOB_RECURSE INCLUDES "include/*.h" "include/*.hpp" "include/*.cpp")
# 指定引用的外部库的搜索路径
LINK_DIRECTORIES("D:\\AppC++\\opencv-4.1.2\\opencv\\build\\x64\\MinGW\\lib")
LINK_DIRECTORIES("./3rd")
# 枚举源文件
aux_source_directory("./src" SOURCES)
# 输出路径
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
# 生成可执行的文件
add_executable(${PROJECT_NAME} ${SOURCES} ${INCLUDES})
# 链接
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
tensorflow.dll
XCDNN.dll
libopencv_calib3d412.dll.a
libopencv_core412.dll.a
libopencv_dnn412.dll.a
libopencv_features2d412.dll.a
libopencv_flann412.dll.a
libopencv_highgui412.dll.a
libopencv_imgcodecs412.dll.a
libopencv_imgproc412.dll.a
libopencv_ml412.dll.a
libopencv_objdetect412.dll.a
libopencv_photo412.dll.a
libopencv_stitching412.dll.a
libopencv_ts412.dll.a
libopencv_video412.dll.a
libopencv_videoio412.dll.a
)