1

I'm trying to build a golang website on Debian 11 but at build time I get this error:

# gocv.io/x/gocv
/usr/bin/ld: cannot find -lopencv_gapi
/usr/bin/ld: cannot find -lopencv_barcode
/usr/bin/ld: cannot find -lopencv_wechat_qrcode
/usr/bin/ld: cannot find -lopencv_xfeatures2d
collect2: error: ld returned 1 exit status

I installed open cv using pip3 install opencv-contrib-python and can confirm that opencv is installed:

python3 -c "import cv2; print(cv2.__version__)"
4.6.0

In Debian 10 on another server I used to built the same codebase without any issues

My go version is go1.16.7 linux/amd64

I have tried many things like export CGO_LDFLAGS=-Wl,--no-as-needed as suggested here but they did not work.

Also, this might be helpful: ld -lzlib --verbose gives:

ld: mode elf_x86_64
attempt to open /usr/local/lib/x86_64-linux-gnu/libzlib.so failed
attempt to open /usr/local/lib/x86_64-linux-gnu/libzlib.a failed
attempt to open /lib/x86_64-linux-gnu/libzlib.so failed
attempt to open /lib/x86_64-linux-gnu/libzlib.a failed
attempt to open /usr/lib/x86_64-linux-gnu/libzlib.so failed
attempt to open /usr/lib/x86_64-linux-gnu/libzlib.a failed
attempt to open /usr/lib/x86_64-linux-gnu64/libzlib.so failed
attempt to open /usr/lib/x86_64-linux-gnu64/libzlib.a failed
attempt to open /usr/local/lib64/libzlib.so failed
attempt to open /usr/local/lib64/libzlib.a failed
attempt to open /lib64/libzlib.so failed
attempt to open /lib64/libzlib.a failed
attempt to open /usr/lib64/libzlib.so failed
attempt to open /usr/lib64/libzlib.a failed
attempt to open /usr/local/lib/libzlib.so failed
attempt to open /usr/local/lib/libzlib.a failed
attempt to open /lib/libzlib.so failed
attempt to open /lib/libzlib.a failed
attempt to open /usr/lib/libzlib.so failed
attempt to open /usr/lib/libzlib.a failed
attempt to open /usr/x86_64-linux-gnu/lib64/libzlib.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/libzlib.a failed
attempt to open /usr/x86_64-linux-gnu/lib/libzlib.so failed
attempt to open /usr/x86_64-linux-gnu/lib/libzlib.a failed
ld: cannot find -lzlib
attempt to open /usr/local/lib/x86_64-linux-gnu/libzlib.so failed
attempt to open /usr/local/lib/x86_64-linux-gnu/zlib.a failed
attempt to open /lib/x86_64-linux-gnu/libzlib.so failed
attempt to open /lib/x86_64-linux-gnu/zlib.a failed
attempt to open /usr/lib/x86_64-linux-gnu/libzlib.so failed
attempt to open /usr/lib/x86_64-linux-gnu/zlib.a failed
attempt to open /usr/lib/x86_64-linux-gnu64/libzlib.so failed
attempt to open /usr/lib/x86_64-linux-gnu64/zlib.a failed
attempt to open /usr/local/lib64/libzlib.so failed
attempt to open /usr/local/lib64/zlib.a failed
attempt to open /lib64/libzlib.so failed
attempt to open /lib64/zlib.a failed
attempt to open /usr/lib64/libzlib.so failed
attempt to open /usr/lib64/zlib.a failed
attempt to open /usr/local/lib/libzlib.so failed
attempt to open /usr/local/lib/zlib.a failed
attempt to open /lib/libzlib.so failed
attempt to open /lib/zlib.a failed
attempt to open /usr/lib/libzlib.so failed
attempt to open /usr/lib/zlib.a failed
attempt to open /usr/x86_64-linux-gnu/lib64/libzlib.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/zlib.a failed
attempt to open /usr/x86_64-linux-gnu/lib/libzlib.so failed
attempt to open /usr/x86_64-linux-gnu/lib/zlib.a failed

I have also tried: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/blnks as suggested here but still get the same erro.

Appreciate your help to resolve this.

blnks
  • 600
  • 5
  • 15
  • 2
    `opencv-contrib-python ` doesn't install OpenCV libraries. Use the command `pip3 show opencv-contrib-python -f` to see the list of files of the package. You need to install the OpenCV yourself. – Pak Uula Oct 26 '22 at 04:04
  • @PakUula I built opencv from source using this guid: https://itslinuxfoss.com/install-opencv-debian/ but still get the same error. – blnks Oct 26 '22 at 04:17
  • It must have installed `so` files somewhere inside `/usr/local/lib`. Check it. Use `sudo ldconfig` to update ld cache. – Pak Uula Oct 26 '22 at 04:59
  • Right, after a complete rebuild using this https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html the problem is resolved. Thanks for your tips dude. – blnks Oct 26 '22 at 05:16

0 Answers0