Reputation: 894
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
Upvotes: 1
Views: 5745
Reputation: 1933
-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)
Upvotes: 4