Linux下基于OpenCV的Cmake工程

edda@edda:~/Documents/OpenCV/opencv_test/cmake_project$ ll
total 32
drwxrwxr-x 3 edda edda 4096 1月  10 14:10 ./
drwxrwxr-x 4 edda edda 4096 1月  10 09:53 ../
-rw-rw-r-- 1 edda edda  455 1月  10 14:10 CMakeLists.txt
-rw-rw-r-- 1 edda edda 9018 1月  10 14:03 lena.jpg
-rw-rw-r-- 1 edda edda  497 1月  10 14:03 main.cpp
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project$ 
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project$ mkdir build
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project$ 
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project$ cp ./lena.jpg ./build/
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project$ 
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project$ vi CMakeLists.txt
#CMakeLists中内容开始
set(OpenCV_DIR "/home/edda/Documents/OpenCV/opencv_install/lib/cmake/opencv4")
find_package(OpenCV REQUIRED)
 
#添加OpenCV头文件
include_directories(${OpenCV_INCLUDE_DIRS})
 
#显示OpenCV_INCLUDE_DIRS的值
message(${OpenCV_INCLUDE_DIRS})
 
# 添加一个可执行程序
# 语法:add_executable( 程序名 源代码文件 )
add_executable( main main.cpp )
 
# 将库文件链接到可执行程序上
target_link_libraries( main  ${OpenCV_LIBS})
#CMakeLists中内容结束

edda@edda:~/Documents/OpenCV/opencv_test/cmake_project$ 
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project$ cd build/
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project/build$ 
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project/build$ cmake ../
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: /home/edda/Documents/OpenCV/opencv_install (found version "4.5.2") 
/home/edda/Documents/OpenCV/opencv_install/include/opencv4
CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.10)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
-- Generating done
-- Build files have been written to: /home/edda/Documents/OpenCV/opencv_test/cmake_project/build
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project/build$ 
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project/build$ make 
Scanning dependencies of target main
[ 50%] Building CXX object CMakeFiles/main.dir/main.o
[100%] Linking CXX executable main
[100%] Built target main
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project/build$ 
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project/build$ ll
total 68
drwxrwxr-x 3 edda edda  4096 1月  10 14:10 ./
drwxrwxr-x 3 edda edda  4096 1月  10 14:10 ../
-rw-rw-r-- 1 edda edda 13186 1月  10 14:10 CMakeCache.txt
drwxrwxr-x 5 edda edda  4096 1月  10 14:10 CMakeFiles/
-rw-rw-r-- 1 edda edda  1558 1月  10 14:10 cmake_install.cmake
-rw-rw-r-- 1 edda edda  9018 1月  10 14:10 lena.jpg
-rwxrwxr-x 1 edda edda 14584 1月  10 14:10 main*
-rw-rw-r-- 1 edda edda  4700 1月  10 14:10 Makefile
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project/build$ 
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project/build$ ./main 
edda@edda:~/Documents/OpenCV/opencv_test/cmake_project/build$ 

你可能感兴趣的:(opencv,linux,c++)