Linking OpenCV library

So i already install OpenCV library two years ago on virtualenviroment for python and it work well using this step. Now i create some image processing program in C languange, but everytime i try to compile, it always couldn't find the OpenCV library.

Package checking always able to detect OpenCV
$ pkg-config --modversion opencv
3.1.0

But if i run my make file

Below my make file, linux.sh

#!/bin/sh
# if [ $# -gt 0 ] ; then
# base=`basename $1`
# echo "compiling $base"
# g++ -ggdb `pkg-config opencv --cflags --libs` $1 -o $base
# if [ $# -gt 0 ] ; then
# base=`basename $1 .c`
# echo "compiling $base"
# gcc -ggdb `pkg-config opencv --cflags --libs` $base.c -o $base
if [ $# -gt 0 ] ; then base=`basename $1 .cpp` echo "compiling $base" g++ -ggdb `pkg-config opencv --cflags --libs` $base.cpp -o $base
else for i in *.c; do echo "compiling $i" gcc -ggdb `pkg-config --cflags opencv` -o `basename $i .c` $i `pkg-config --libs opencv` -lm; done for i in *.cpp; do echo "compiling $i" g++ -ggdb `pkg-config --cflags opencv` -o `basename $i .cpp` $i `pkg-config --libs opencv` -lm; done
fi

It always return this

compiling main.c
/usr/bin/ld: cannot find -lopencv_aruco
/usr/bin/ld: cannot find -lopencv_bgsegm
/usr/bin/ld: cannot find -lopencv_bioinspired
/usr/bin/ld: cannot find -lopencv_ccalib
/usr/bin/ld: cannot find -lopencv_dnn
/usr/bin/ld: cannot find -lopencv_dpm
/usr/bin/ld: cannot find -lopencv_fuzzy
/usr/bin/ld: cannot find -lopencv_line_descriptor
/usr/bin/ld: cannot find -lopencv_optflow
/usr/bin/ld: cannot find -lopencv_plot
/usr/bin/ld: cannot find -lopencv_reg
/usr/bin/ld: cannot find -lopencv_saliency
/usr/bin/ld: cannot find -lopencv_stereo
/usr/bin/ld: cannot find -lopencv_structured_light
/usr/bin/ld: cannot find -lopencv_rgbd
/usr/bin/ld: cannot find -lopencv_surface_matching
/usr/bin/ld: cannot find -lopencv_tracking
/usr/bin/ld: cannot find -lopencv_datasets
/usr/bin/ld: cannot find -lopencv_text
/usr/bin/ld: cannot find -lopencv_face
/usr/bin/ld: cannot find -lopencv_xfeatures2d
/usr/bin/ld: cannot find -lopencv_shape
/usr/bin/ld: cannot find -lopencv_ximgproc
/usr/bin/ld: cannot find -lopencv_xobjdetect
/usr/bin/ld: cannot find -lopencv_xphoto
/usr/bin/ld: cannot find -lopencv_videoio
/usr/bin/ld: cannot find -lopencv_imgcodecs
collect2: error: ld returned 1 exit status

I search where my OpenCV library located, and i found it in /usr/local/lib : It contain everything that needed such as libopencv_aruco.so.3.1, libopencv_bgsegm.so.3.1 and etc.

I have try several solution online but it still not working. So, how could i solve this problem without ruining my entire system that still working fine?

Update #1Result from pkg-config --libs opencv

-L/usr/local/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn -lopencv_dpm -lopencv_fuzzy -lopencv_line_descriptor -lopencv_optflow -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lippicv -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core

I try one solution from again here :

Step i did :

sudo gedit /etc/ld.so.conf.d/Robotika.conf

And in that, i type this

/usr/local/lib

After that

sudo ldconfig

OK BASED on comment, this solution is not for my case

Update #2When i run

$ namei -l /usr/local/lib/libopencv_aruco.so
f: /usr/local/lib/libopencv_aruco.so
drwxr-xr-x root root /
drwxr-xr-x root root usr
drwxr-xr-x root root local
drwxr-xr-x root root lib libopencv_aruco.so - No such file or directory

library not detected, but if i run :

$ namei -l /usr/local/lib/libopencv_aruco.so.3.1
f: /usr/local/lib/libopencv_aruco.so.3.1
drwxr-xr-x root root /
drwxr-xr-x root root usr
drwxr-xr-x root root local
drwxr-xr-x root root lib
lrwxrwxrwx root root libopencv_aruco.so.3.1 -> libopencv_aruco.so.3.1.0
-rw-r--r-- root root libopencv_aruco.so.3.1.0

it detected.

9 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like