How can I compile Opencv API on gcc
12,705
Solution 1
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
Solution 2
Try below command
gcc -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binary main.c -lopencv_core -lopencv_imgproc -lopencv_highgui
Assumes OpenCV installed on /usr/local directory.
Related videos on Youtube
Author by
user3064089
Updated on September 16, 2022Comments
-
user3064089 over 1 year
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 compilationgcc 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.