Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem.. /usr/bin/ld: cannot find -lopencv_imgcodecs #4942

Closed
ghost opened this issue Nov 1, 2016 · 30 comments
Closed

problem.. /usr/bin/ld: cannot find -lopencv_imgcodecs #4942

ghost opened this issue Nov 1, 2016 · 30 comments

Comments

@ghost
Copy link

ghost commented Nov 1, 2016

Hi..

My machine spec..
Ubuntu 16.04 LTS
python 2.7, opencv 2.4.11

I tried to compile py-faster-rcnn -> make -j8 && make pycaffe

and..... build failed..

CXX examples/cpp_classification/classification.cpp
CXX .build_release/src/caffe/proto/caffe.pb.cc
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: cannot find -lopencv_imgcodecs
collect2: error: ld returned 1 exit status
Makefile:570: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1

I added to Makefile opencv_imgcodecs, but still problem..

help me.. thanks.

@abuccts
Copy link

abuccts commented Nov 2, 2016

opencv_imgcodecs is needed and available in opencv 3.0+.
You don't need to link it if using version 2.4.11.
Please refer to line 194-199 in Makefile.

@thelittlekid
Copy link

@Mjgo, have you fixed it?
@abuccts, I got the same error message after commenting those lines in Makefile. What else did you do?
Thanks.

@Po-Hsuan-Huang
Copy link

seems like @Mjgo was using opencv2.4
I got the same problem when installing with opencv3.0+ and CUDA on Ubuntu 16.04
I also added opencv_imgcodescs and opencv_videoio to my Makefile but not solving the issue.

My error message

nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).

AR -o .build_release/lib/libcaffe.a

LD -o .build_release/lib/libcaffe.so.1.0.0-rc3

/usr/bin/ld: cannot find -lopencv_imgcodecs

/usr/bin/ld: cannot find -lopencv_videoio

collect2: error: ld returned 1 exit status

Makefile:566: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed

make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1

My setting in Makefile

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5 opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio

# handle IO dependencies
USE_LEVELDB ?= 1
USE_LMDB ?= 1
USE_OPENCV ?= 1

ifeq ($(USE_LEVELDB), 1)
        LIBRARIES += leveldb snappy
endif
ifeq ($(USE_LMDB), 1)
        LIBRARIES += lmdb
endif
ifeq ($(USE_OPENCV), 1)
        LIBRARIES += opencv_core opencv_highgui opencv_imgproc

        ifeq ($(OPENCV_VERSION), 3)
                LIBRARIES += opencv_imgcodecs
        endif

My Makefile.config

## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!

# cuDNN acceleration switch (uncomment to build with cuDNN).
 USE_CUDNN := 1

# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1

# uncomment to disable IO dependencies and corresponding data layers
 USE_OPENCV := 3
# USE_LEVELDB := 0
# USE_LMDB := 0

# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
#	You should not set this flag if you will be reading LMDBs with any
#	possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1

# Uncomment if you're using OpenCV 3
 OPENCV_VERSION := 3

# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++

# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda-8.0
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
		-gencode arch=compute_20,code=sm_21 \
		-gencode arch=compute_30,code=sm_30 \
		-gencode arch=compute_35,code=sm_35 \
		-gencode arch=compute_50,code=sm_50 \
		-gencode arch=compute_52,code=sm_52 \
		-gencode arch=compute_60,code=sm_60 \
		-gencode arch=compute_61,code=sm_61 \
		-gencode arch=compute_61,code=compute_61

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas

# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
		/usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
		# $(ANACONDA_HOME)/include/python2.7 \
		# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include

# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# PYTHON_INCLUDE := /usr/include/python3.5m \
#                 /usr/lib/python3.5/dist-packages/numpy/core/include

# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib
 PYTHON_LIB := $(ANACONDA_HOME)/lib

# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

# Uncomment to support layers written in Python (will link against Python libs)
 WITH_PYTHON_LAYER := 1

# Whatever else you find you need goes here.

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial /usr/local/share/OpenCV/3rdparty/lib/

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial


# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib

# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1

# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute

# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1

# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0

# enable pretty build (comment to see full commands)
Q ?= @

@shelhamer
Copy link
Member

From https://github.com/BVLC/caffe/blob/master/CONTRIBUTING.md:

Please do not post usage, installation, or modeling questions, or other requests for help to Issues.
Use the caffe-users list instead. This helps developers maintain a clear, uncluttered, and efficient view of the state of Caffe.

@YuYuYan
Copy link

YuYuYan commented Apr 14, 2017

@Mjgo @abuccts @Po-Hsuan-Huang Did you already fixed the problem? I got the same problem....
cannot find -lopencv_imagecodecs

@lvzongting
Copy link

comment this line OPENCV_VERSION := 3 will be ok.

@shubhamgoel27
Copy link

I have the same error. I've included the mentioned libraries in Makefile.config and Makefile. Any solution would be appreciated.

@duygusar
Copy link

duygusar commented Dec 8, 2017

I have the same error "/usr/bin/ld: cannot find -lopencv_imgcodecs
collect2: error: ld returned 1 exit status
Makefile:572: recipe for target '.build_release/lib/libcaffe.so.1.0.0' failed"

I have Opencv 3.3

@mbronek7
Copy link

mbronek7 commented Dec 9, 2017

I have the same problem:
LD -o .build_release/lib/libcaffe.so.1.0.0
/usr/bin/ld: cannot find -lopencv_imgcodecs
collect2: error: ld returned 1 exit status
Makefile:572: recipe for target '.build_release/lib/libcaffe.so.1.0.0' failed

@koujan
Copy link

koujan commented Dec 12, 2017

Has anybody figured out how to fix this issue!?

@mbronek7
Copy link

I tried but I wasn't able to figure out how to fix it and I asked this question on Caffe Users Group also now answers

@duygusar
Copy link

duygusar commented Dec 12, 2017

@koujan @mbronek7
I was able to fix this, but I am not sure what worked exactly since I didn't take notes, as far as I remember

  1. First, make sure you run this to satisfy all python requirements
    sudo sh -c 'for req in $(cat requirements.txt); do pip install $req; done'

2.Then Follow the answer to this question religiously (for OpenCV 3.3 at least but possibly for 3.2 as well):
https://stackoverflow.com/questions/46584000/cmake-error-variables-are-set-to-notfound

@shubhamgoel27
Copy link

Managed to solve it.

Added the OpenCV lib path to the LIBRARY_DIRS in my Makefile.config.

@mbronek7
Copy link

mbronek7 commented Dec 12, 2017

How to do it: I tried sth like:

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial usr/include/opencv2
but it doesn't work
I am using Ubuntu based distribution of Linux.

@shubhamgoel27
Copy link

I did this

LIBRARY_DIRS:= ~/opencv-3.3.0/build/lib

Note: This is not the opencv which gets installed in /usr/include but the original opencv where I used make.

@ZubairKhan001
Copy link

run these commands

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler

sudo apt-get install --no-install-recommends libboost-all-dev

do
make clean
and then do this if your pc has 8 cores, process will be fast

make all -j8
make runtest -j8
make pycaffe

hope it helps.

@Kongsea
Copy link

Kongsea commented Feb 12, 2018

@Laowai01 Sorry, the method you mentioned did not work.

@Kongsea
Copy link

Kongsea commented Feb 12, 2018

I finally found it's because I uncomment this line in my Makefile.config file:
# OPENCV_VERSION := 3
But I used opencv2 actually.
After comment this line, everything is OK.

@Yumin-Sun-00
Copy link

Why you are using opencv2 not opencv3?

@Yumin-Sun-00
Copy link

comment opencv = 3 line, it works for me, but who knows what kind of consequences it will have in the future, maybe need to reinstall with cuda8...But, than everything need to reinstall...s..h...i...t....

@Kongsea
Copy link

Kongsea commented Mar 7, 2018

My project needs to use opencv2. So I don't have the uncertain consequences as you.

@huanglianghua
Copy link

I think I finally figured out. For some versions of OpenCV3 (mine OpenCV 3.1.0), there's only a libopencv_world.so (and no others such as libopencv_imgcodecs.so). So I comment the following lines in Makefile:

# ifeq ($(USE_OPENCV), 1)
#       LIBRARIES += opencv_core opencv_highgui opencv_imgproc

#       ifeq ($(OPENCV_VERSION), 3)
#               LIBRARIES += opencv_imgcodecs
#       endif
#
# endif

and add another line below:

LIBRARIES += opencv_world

Everything works fine for me.

@eyildiz-ugoe
Copy link

The problem is still there, I am using OpenCV 3.4

@danpe1327
Copy link

find where you install opencv3.x, then excute:
sudo ldconfig /path/to/libopencv*.so
such as,
sudo ldconfig /usr/local/lib
it works for me .

@jmarrr
Copy link

jmarrr commented Dec 12, 2018

I followed the instruction but when I make all I get this error /usr/bin/ld: cannot find -lextra_component-NOTFOUND

@scutzhe
Copy link

scutzhe commented Mar 13, 2019

opencv_imgcodecs is needed and available in opencv 3.0+.
You don't need to link it if using version 2.4.11.
Please refer to line 194-199 in Makefile.

opencv-python 3.4.5.20 don't work on me

@angrypiggy
Copy link

It took me a week to solve this problem... I want to share my solution with you in detail so fewer people would get stuck with this situation.

In my case, the problem lies in the conflict between opencv2 and opencv3. My ubuntu was installed with opencv 2.4.9 before by someone else, but I didn't manage to find the build file of it and uninstall it. I learned somewhere that 'imgcodecs' only exists in opencv 3+, so I realized that caffe must have used opencv2 and then run into this mistake.

I used cmake-gui to install opencv 3.4.3 (without clicking BUILD_opencv_world), and CMAKE_INSTALL_PREFIX was set to usr/local/opencv343 (whatever u like, just set to be separated from opencv2, which was installed in the default path). Then add usr/local/opencv343/lib to 'sudo gedit /etc/ld.so.conf.d/opencv.conf', and add 'PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH' to 'sudo gedit /etc/bash.bashrc'.

Then put 'usr/local/opencv343/include' and 'usr/local/opencv343/lib' behind the '(PYTHON INCLUDE)' and '(PYTHON LIB)' in the makefile.config respectively (before other paths).

This works for me, where my ubuntu has both opencv 2 and 3. Hope it would work for you guys too.

@eezywu
Copy link

eezywu commented Apr 21, 2019

I commented the following code in the file Makefile, and solved the problem.

       ifeq ($(OPENCV_VERSION), 3)
              LIBRARIES += opencv_imgcodecs
       endif

@pavelbadin
Copy link

If you follow Xilinx the tutorial (https://github.com/Xilinx/Edge-AI-Platform-Tutorials/tree/master/docs/Darknet-Caffe-Conversion), the solution from eezywu works perfectly! Thanks!

@avinmaulana
Copy link

avinmaulana commented Feb 25, 2020

Found the solution
I use opencv 2 on ubuntu 16.04
on Makefile.config
# OPENCV_VERSION := 3

on Makefile

#       ifeq ($(OPENCV_VERSION), 3)
#               LIBRARIES += opencv_imgcodecs
#       endif

and if on the upper thereis opencv_imagecodecs on LIBRARIES, just comment on the opencv_imagecodecs part only

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests