1

So I am not working on a computer but on an embedded device running ubuntu.

I am trying to compile openCV code but I have the feeling that I am in a deadlock!

This is the error I get: problem:

/usr/bin/ld: warning: libopencv_core.so.3.2, needed by //usr/local/lib/libopencv_imgcodecs.so, may conflict with libopencv_core.so.2.4
/usr/bin/ld: /tmp/ccYlsBYW.o: undefined reference to symbol '_ZN2cv11setIdentityERKNS_17_InputOutputArrayERKNS_7Scalar_IdEE'
/usr/local/lib//libopencv_core.so.3.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

rename 2.4 libraries:

ubuntu@tegra-ubuntu:/usr/lib$ sudo mv libopencv_core.so libopencv_core.soMyOld
ubuntu@tegra-ubuntu:/usr/lib$ sudo mv libopencv_core.so.2.4 libopencv_core.so.2.4MyOld
ubuntu@tegra-ubuntu:/usr/lib$ sudo mv libopencv_core.so.2.4.10 libopencv_core.so.2.4.10MyOld

recompile code

/usr/bin/ld: warning: libopencv_core.so.2.4, needed by /usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../../lib/libopencv_imgproc.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libopencv_imgproc.so.3.2, needed by //usr/local/lib/libopencv_imgcodecs.so, may conflict with libopencv_imgproc.so.2.4
/usr/bin/ld: /tmp/ccmcvWug.o: undefined reference to symbol '_ZN2cv6circleERKNS_17_InputOutputArrayENS_6Point_IiEEiRKNS_7Scalar_IdEEiii'
/usr/local/lib//libopencv_imgproc.so.3.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

renaming 3.2 libraries:

ubuntu@tegra-ubuntu:/usr/local/lib$ sudo mv libopencv_core.so 
ubuntu@tegra-ubuntu:/usr/local/lib$ sudo mv libopencv_core.so.3.2 libopencv_core.so.3.2MyOld
ubuntu@tegra-ubuntu:/usr/local/lib$ sudo mv libopencv_core.so.3.2.0 libopencv_core.so.3.2.0MyOld

recompile

/usr/bin/ld: warning: libopencv_core.so.3.2, needed by //usr/local/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libopencv_imgproc.so.3.2, needed by //usr/local/lib/libopencv_imgcodecs.so, may conflict with libopencv_imgproc.so.2.4
/usr/bin/ld: /tmp/cclHSHtB.o: undefined reference to symbol '_ZN2cv6circleERKNS_17_InputOutputArrayENS_6Point_IiEEiRKNS_7Scalar_IdEEiii'
/usr/local/lib//libopencv_imgproc.so.3.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

What can I do to solve this issue? Uninstalling everything and reinstalling is not an option...

EDIT:

I compile with this command:

g++ src/personDetection.cpp src/personRecognition.cpp main.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lopencv_calib3d -lopencv_features2d -lopencv_video -lopencv_videoio -pthread -o main
  • I guess you are on a tegra board. Maybe you should remove the default installed OpenCV library: `OpenCV4Tegra`. – nglee Jun 06 '17 at 13:35
  • @devnglee "maybe"? Why aren't you sure? Btw notice that the errors aren't about opencv version 4 like the one you are referring to and on my board there was no default installed openCV. – LandonZeKepitelOfGreytBritn Jun 06 '17 at 13:44
  • `opencv4tegra` stands for opencv for tegra. Forget about that if your board didn't have that. So you have 2.4 installed already and tries to install 3.2? – nglee Jun 06 '17 at 13:48
  • @devnglee I made some mistake during the installation (long time ago) and ended up installing another version of openCV (don't remember what the issue was and what I ended up doing). Today suddenly, when trying to compile my openCV code I het this error and am unable to compile my code. (I have been able to compile it for many months untill today, I don't understand what happened) – LandonZeKepitelOfGreytBritn Jun 06 '17 at 13:56
  • Maybe library paths given to compiler are messed up. You should tell your compiler to use only one version. It is hard to figure out what exactly went wrong with the informations you've provided. – nglee Jun 06 '17 at 14:17
  • @devnglee how should I tell this to my compiler? What extra info do you need? – LandonZeKepitelOfGreytBritn Jun 06 '17 at 14:17
  • 1
    You can search the web for yourself but here is a simple example: `g++ -L/usr/lib main.cpp -lopencv_core -lopencv_imgcodecs` this will search for `libopencv_core.so` and `libopencv_imgcodecs.so` from `/usr/lib` and linker will link that library to your code. – nglee Jun 06 '17 at 14:25
  • That worked!! Feel free to post it below and I'll accept your answer. What's the difference between -L and -I? Why did that work? – LandonZeKepitelOfGreytBritn Jun 06 '17 at 14:29

1 Answers1

4

-L option is used to specify the directory path. Compiler will search this directory with other system standard directories, such as directories in LIBRARY_PATH. But it searches directories specified with -L first.

-l option is used to specify the name of the library.

In your case, 2.4 version libraries are in /usr/lib and 3.2 version libraries are in /usr/local/lib. Your code, probably, is expecting 2.4 version, but your system may be set to search /usr/local/lib before searching /usr/lib and this may be the cause of your problem.

By specifying -L/usr/lib you are telling compiler to search /usr/lib first, resulting in using 2.4 version libraries.


UPDATE

$ gcc -m64 -Xlinker --verbose  2>/dev/null | grep SEARCH | sed 's/SEARCH_DIR("=\?\([^"]\+\)"); */\1\n/g'  | grep -vE '^$'

Above command will show you the list of default searched directories when linking. (copied the command from this article)

In my machine(Ubuntu 16.04, 64-bit), /usr/local/lib appears before /usr/lib. This means that a library in /usr/local/lib can override libraries in /usr/lib. (link)

nglee
  • 1,913
  • 9
  • 32