Compiling and executing OpenCV programs written in C++

Compiling and executing C++ programs

  • Browse to the directory of your cpp program and open a terminal in that folder.

  • Create a CMake file name CMakeLists.txt in the same directory as your project :

              cmake_minimum_required(VERSION 2.8)
              project( ProjectName )
              find_package( OpenCV REQUIRED )`
              add_executable( ProjectName your_program_main_file.cpp )
              target_link_libraries( ProjectName ${OpenCV_LIBS} ) 
  • Now we can generate the executable so as to run the program. To do so execute
 cmake .

followed by

 make 

on the terminal. The execution will run successfully and create binaries if there are no errors.

  • To execute your compiled program enter ./ProjectName

Ashwin Phadke
Ashwin Phadke
Computer Vision | Deep Learning

Ashwin has more than 1.2 years of professional and mentoring experience in deep learning, computer vision and NLP.

Next

Related