Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I compile Opencv API on gcc

I am trying to compile an an .C file which contains API from Opencv library.
It seems the compiler doesn't find the API. I use the normal command for compilation

   gcc new.c -c
   gcc new.o -o new1 -l highgui  

highgui is a .h file which is calling other .h files from Opencv lib

I think I have the same problem as the thread below as I get almost same error.

GCC: How can I make this compiling and linking work?

like image 992
user3064089 Avatar asked Mar 21 '23 10:03

user3064089


1 Answers

You can use pkg-config command to get the compiler/linker options. Like this

gcc `pkg-config --cflags opencv` `pkg-config --libs opencv` new.c

Please note the above punctuation is ` not '.

Or you can use CMake. Write a CMakeLists.txt like this

cmake_minimum_required (VERSION 2.6)
project (new1)
find_package (OpenCV REQUIRED)
include_directories (${OpenCV_INCLUDE_DIRS})
add_executable (new1 new.c)
target_link_libraries (new1 ${OpenCV_LIBS})

then you can build like this

mkdir build
cd build
cmake -DOpenCV_DIR=<the-directory-contating-OpenCVConfig.cmake> ..
make
like image 89
Yantao Xie Avatar answered Mar 28 '23 17:03

Yantao Xie