Ask Your Question
0

/ust/bin/ld: cannot find -lopencv_imgcodecs

asked 2020-03-21 02:30:32 -0500

andrei186 gravatar image

updated 2020-03-22 09:37:20 -0500

Freshly installed Ubuntu 18 and OpenCV C++ (version 3.4.10)
Attempt to compile decolor.cpp from the installed samples using:

g++ -std=c++11 decolor.cpp -o fish -I /home/a/Downloads/installation/OpenCV-3.4/include -L /home/a/Downloads/installation/OpenCV-3.4/lib -lopencv_core -lopencv_highgui

aborts with the error:

/usr/bin/ld: /tmp/ccN7bflL.o: undefined reference to symbol '_ZN2cv6imreadERKNS_6StringEi'
//home/a/Downloads/installation/OpenCV-3.4/lib/libopencv_imgcodecs.so.3.4: error adding symbols: DSO missing from command line
  collect2: error: ld returned 1 exit status

I would not ask about symbol '_ZN2cv6imreadERKNS_6StringEi' gobbledegook. But what is DSO and what it has to do with the command line?

Google brings suggestions that this is because I might have two versions of openCV installed and should uninstall one.
I installed openCV using .sh script downloaded from

 www.learnopencv.com/install-opencv-3-4-4-on-ubuntu-18-04/

Is there in this code anything which could cause installation of libraries belonging to different openCV versions?

Installation went with no errors

pkg-config --modversion opencv returns: 3.4.10

If indeed I have two openCV how shall I uninstall one of them as suggested?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2020-03-23 17:19:29 -0500

updated 2020-03-26 00:49:35 -0500

There's a lot to unpack here, so I'll go section-by-section:

NOTE: This is long enough that it's collapsed by default. Don't overlook the little (more) link at the end.

But what is DSO and what it has to do with the command line?

"DSO" is short for "Dynamic Shared Object" and it's platform-agnostic jargon for a .so, .dylib, or .dll file, as fits the platform.

I've written almost no C++ (Python mainly), but I believe "error adding symbols: DSO missing from command line" means "Your code references this library, but you didn't ask me to link it in. I don't know which one was a mistake, so please either edit your code to not use it or add a -l for it to your g++ ... command and try again."

I would not ask about symbol '_ZN2cv6imreadERKNS_6StringEi' gobbledegook.

I should probably explain it anyway. ld uses a symbol name lookup system that predates C++ and only work on strings for names, so, when multiple functions or methods have the same name, differing only in their arguments or what class they belong to, they need to be disambiguated.

I won't give a full guide to decoding _ZN2cv6imreadERKNS_6StringEi but I will point out the imread in the middle of it. The gobbledegook is how ld sees the version of imread that your code is trying to call.

I installed openCV using .sh script downloaded from

A quick caution. It doesn't look like you ran make install but, if you ever want to, I advise installing checkinstall and running that instead. It'll give you a wizard for building a .deb package from make install and then install it for you, making it easy to uninstall with sudo apt remove PACKAGE_NAME or track what got installed with dpkg -L PACKAGE_NAME.

find / -name opencv_imgcodecs

-name does exact string matching, so find / -name opencv_imgcodecs (without any wildcards) should return no results.

If you've had time for your nightly updatedb run to occur since installing your libraries, I'd suggest locate opencv_imgcodecs as the fastest solution for finding them. (locate does substring matching, so no wildcards are needed)

...bearing in mind that, if you move a file, locate won't know until the next updatedb.

Another quick solution which will only cover stuff installed by checkinstall or distro-provided packages but which will tell you the name of the package providing it is dpkg -S opencv_imgcodecs.

Mine produces this output:

$ dpkg -S opencv_imgcodecs
opencv3: /usr/local/lib/libopencv_imgcodecs.so.3.2
opencv3: /usr/local/lib/libopencv_imgcodecs.so
opencv3: /usr/local/lib/libopencv_imgcodecs.so.3.2.0

(I could then get additional information by running apt-cache show opencv3 and apt-cache showpkg opencv3)

If you really must take the slowest approach, using find, my suggestion is to use this command:

for X in /{lib,usr/lib,usr/local/lib,home}; do find "$X" -name '*opencv_imgcodecs*'; done

It's equivalent to doing this, and will avoid wasting time checking places ... (more)

edit flag offensive delete link more

Comments

1

Hi, Stephan! Your post is a real goldmine. I digged throuh a pile of websites and found nothing like that as if you are disclosing secrets which other tutors hide! Thank a lot for spanding you time for writing this detailed manual which sure will be of great help for other newbies and not only newbies.

Not everything you said I understood, but this is an excrellent entry point. Actually there is one subject I should know to use openCV? and to which, to my surprise, I failed to find an answer on the Web: the OpenCV directories structure. I will ask this question in a separate thread - perhaps you would attend if you have time and desire

andrei186 gravatar imageandrei186 ( 2020-03-24 10:17:28 -0500 )edit
0

answered 2020-03-21 02:57:50 -0500

berak gravatar image

I would not ask about symbol '_ZN2cv6imreadERKNS_6StringEi' gobbledegook

however, it should tell you, you're lacking the resp. library (and probably a few more)

add -lopencv_imgcodecs to your cmdline to fix the imread() problem.

edit flag offensive delete link more

Comments

thank you. The reason for "DSO missing from command line" referring to libopencv_imgcodecs.so.3.4 seems indeed to be caused by libopencv_imgcodecs.so.3.4 and libopencv_imgcodecs.so.3.4.10 sitting in the same lib directory.

After libopencv_imgcodecs.so.3.4 was moved out this error has been replaced by a number of "undefined reference to 'cv::imread()' and other funcltions nameWindow(), imshow() and waitkey() used in the cpp.

As you suggested I added -lopencv_imgcodecs to the command line, yet it returned

/ust/bin/ld: cannot find -lopencv_imgcodecs

find / -name opencv_imgcodecs finds nothing

Does it mean that opencv_imgcodecs is not installed? If it does, how shall I install it?

PS.

-lopencv_core does not cause errors though find opencv_imgcodecs too finds nothing

andrei186 gravatar imageandrei186 ( 2020-03-22 09:07:37 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-03-21 02:30:32 -0500

Seen: 632 times

Last updated: Mar 26 '20