How can I compile Opencv API on gcc

gcc, header, linker, opencv

Solution

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

Problem

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?

Original source

Related problems