linux compilation - conflicting libraries - c++

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

-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)

Related

PoDoFo setup with eclipse , Linker error, undefined reference to symbol 'pthread_mutexattr_settype##GLIBC_2.2.5'

I'm trying to set up PoDoFo for C++ in Eclipse
OS - Ubuntu 16.04 LTS
Podofo link - http://podofo.sourceforge.net/download.html
I downloaded the latest version and performed the following stpes
mkdir podofo-build
cd podofo-build
cmake ../podofo
make
su
make install
everything works fine till this point.
This create a libpodofo.a file in my /usr/local/lib directory
In Eclipse
Under C++ linker I added Library search path(-L) as /usr/local/lib
and in Libraries(-l) I added podofo
Then I ran a Hello world example for podofo
Link : http://podofo.sourceforge.net/examplehelloworld_cpp.html
make all
Building target: opencvtest
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -L/lib/x86_64-linux-gnu -o"opencvtest" ./src/opencvtest.o ./src/podofo_test.o -lopencv_imgcodecs -lpodofo -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_flann
/usr/bin/ld: /usr/local/lib/libpodofo.a(PdfEncodingFactory.cpp.o): undefined reference to symbol 'pthread_mutexattr_settype##GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
makefile:45: recipe for target 'opencvtest' failed
collect2: error: ld returned 1 exit status
make: *** [opencvtest] Error 1
Ldconfig -p gives me following :
ldconfig -p | grep pthread.so
grep: warning: GREP_OPTIONS is deprecated; please use an alias or script
libpthread.so.0 (libc6,x86-64, OS ABI: Linux 2.6.32) => /lib/x86_64-linux-gnu/libpthread.so.0
libgpgme-pthread.so.11 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libgpgme-pthread.so.11
Can someone please help me getting rid of this error , what configuration should I add to resolve this, any suggested reads are also welcomed.
Please let me know if any other info is required. Thanks in advance.
Here is what I was asking exactly.
In eclipse go to Project->c/c++ build-> GCC C++ linker -> Libraries
under Libraries (-l) section add your library in my case it was libpthread.so.0 so you'll be adding pthread Screenshot
for anyone having problems with PoDoFo (ie only libpodofo.a file generated )
add the following libs :
podofo
pthread jpeg z fontconfig freetype

usr/bin/ld: cannot find -lexpat

I am trying compile a software with Scons I get an error saying,
usr/bin/ld: cannot find -lexpat
Can you please tell me how can I fix it? Thank you very much. Here's the full error message:
scons: Reading SConscript files ...
We're on a 64-bit machine
use 32-bit libs & executables even on 64 bit system
OSNAME = Linux-x86_64-32
No installation being done
scons: done reading SConscript files.
scons: Building targets ...
g++ -o src/examples/.Linux-x86_64-32/dana -m32 src/examples/.Linux-x86_64-32/dana.o -Lsrc/libsrc/.Linux-x86_64-32 -Lsrc/libsrc -Lsrc/libsrc++/.Linux-x86_64-32 -Lsrc/libsrc++ -levioxx -levio -lpthread -lexpat -lz -ldl -lm
/usr/bin/ld: cannot find -lexpat
collect2: error: ld returned 1 exit status
scons: *** [src/examples/.Linux-x86_64-32/dana] Error 1
scons: building terminated because of errors.
Below solution worked with me on Ubuntu 20.04:
sudo apt install libexpat-dev
I have had this same problem in Fedora 34. Doing
sudo yum install expat-devel
will solve the problem.

linking things in c++ using object file

PROBLEM SOLVED:::
I am using LEDA library in c++.
command used to make object file.
g++ -I$LEDAROOT/incl -c mult.cpp
this command runs fine
I am getting eroor while linking step.
HERE IS THE EROOR
varun#Kinley:~/Documents/LEDA/test/numbers$ g++ -L$LEDAROOT mult.o -lleda -lX11 -lm
/usr/bin/ld: cannot find -lX11
collect2: error: ld returned 1 exit status
I think I need to install some package,because when I googled this error the most of problems are solved by installing some package .
I didn't find lx11 error
some of the eroor messages that I googled.
error 1
/usr/bin/ld: cannot find -lfreetype collect2: ld returned 1 exit
status
error 2
/usr/bin/ld: cannot find -lz collect2: ld returned 1 exit status
Links where I find these posts
http://www.qtcentre.org/threads/21069-collect2-ld-returned-1-exit-status
http://www.cyberciti.biz/faq/centos-rhel-redhat-usrbinld-cannot-findlc-error/
Do I need to install some package or there is some other problem
Could be two things
1) The X11 library is installed in a non-standard path. Use the search command to see if libX11.a or libX11.so is available on your system. If yes add the directory path to the -L option.
2) You are missing the libX11 library.
In this case, login as admin and use yum (assuming linux) to install this library.
Eg:
"yum install libX11.i386" or "yum install libX11.x86_64", depending on your architecture (32 bit or 64 bit).

Cannot find lffi - Error linking with llvm libraries

I am trying to use LLVM as backend for my compiler, and while linking with the llvm libraries, I get this error
g++ obj/*.o `llvm-config --ldflags core jit native` `llvm-config --libs core jit native` -lfl -o Icarus
/usr/bin/ld: cannot find -lffi
collect2: ld returned 1 exit status
I have installed llvm on my system and my cpp files compile fine. Its during linking that the library its searching can't be found.
If on a deb system try installing the dev libs, they solved the problem for me:
sudo apt-get install libffi-dev
Hmm. Did you install libffi too?
ftp://sourceware.org/pub/libffi/libffi-3.0.10.tar.gz
I know that installing libffi into /usr prefix helped me, when ld complained about being unable to find -ffi

g++ -m32 can not find libstdc++ on debian amd64

I got the following error when compiling a simple hello world program on debian amd64 wheezy(testing) with g++ -m32:
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
I don't have any problems with gcc -m32. I also installed lib32stdc++ package, but it does not seem to work. Thanks.
Pretty sure you need to install g++-4.6-multilib (it would appear you already have gcc-4.6-multilib).
Try installing ia32-libs-dev package.