vscode与Cmake基本使用
- 下载插件
- Ctrl+Shift+p打开VSCode的指令面板,然后输入cmake:q,VSCode会根据输入自动提示,然后选择CMake: Quick Start
- 选择编译器
- 根据提示输入项目名称
- 选择可执行文件
- 编译项目
-
方式一:执行命令
bashcd build cmake ..
-
方式二: VSCode提供了更便捷的方式(点击底部的Build)
-
opencv 配置
-
cmake文件内容
bashmessage(STATUS "Setting up OpenCV libs for: ${CMAKE_CURRENT_SOURCE_DIR}") message(STATUS "source dir: ${CMAKE_SOURCE_DIR}") include_directories("D:/MyWork/tools/dl_deploy_cpp-main/include/opencv4/") link_directories("D:/MyWork/tools/4.8.1/") set(OpenCV_LIBS opencv_world opencv_3rdparty) message(STATUS "Setting up OpenCV libs done! OpenCV_LIBS:+[${OpenCV_LIBS}]")
-
txt文件内容
bashcmake_minimum_required(VERSION 3.0.0) project(demo VERSION 0.1.0 LANGUAGES C CXX) add_executable(demo main.cpp) # set(CPACK_PROJECT_NAME ${PROJECT_NAME}) # set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) # include(CPack) option(INCLUDE_OPENCV "package OpenCV into dl_deploy." ON) message(STATUS "INCLUDE_OPENCV: ${INCLUDE_OPENCV}") # opencv, add library if (INCLUDE_OPENCV) include(opencv.cmake) endif () message(STATUS "libs is: ${OpenCV_LIBS}") if (INCLUDE_OPENCV) target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS}) endif ()