链接 OpenCV 库

链接 OpenCV 库

所以我两年前已经在 python 的虚拟环境中安装了 OpenCV 库,并且它运行良好步骤。现在我用 C 语言创建了一些图像处理程序,但每次我尝试编译时,它总是找不到 OpenCV 库。

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

但是如果我运行我的 make 文件

在我的 make 文件下面,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

它总是返回这个

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

我搜索了我的 OpenCV 库的位置,并在 /usr/local/lib 中找到了它:它包含所需的一切,例如 libopencv_aruco.so.3.1、libopencv_bgsegm.so.3.1 等。

我尝试了网上的几种解决方案,但仍然不起作用。那么,我该如何解决这个问题呢?不会破坏我的整个系统还能正常工作吗?

更新 #1 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

我再次尝试一种解决方案这里

我执行的步骤:

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

然后我输入以下内容

/usr/local/lib

在那之后

sudo ldconfig

好的,根据评论,这个解决方案不适合我的情况

更新 #2 当我跑步时

$ 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

未检测到库,但如果我运行:

$ 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

它检测到了。

相关内容