LIbrary not found but ldd shows it - fortran

I'm compiling a piece of fortran code with intel compilers, everything goes smooth until I try to execute the compiled executable which gives a:
error while loading shared libraries: libimf.so: cannot open shared object file: No such file or directory
[FAIL]
However, the missing library library is linked to the executable, as shown by ldd
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f176d848000)
libimf.so => /opt/intel/compilers_and_libraries_2016.0.109/linux/compiler/lib/intel64/libimf.so (0x00007f176d350000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f176d04a000)
Any ideia on how to fix it?
Thanks

Related

Library not linked even though present in link targets

I'm trying to build an application using cmake but the executable is unable to link to the libraries, the ldd of my executable looks like this
linux-vdso.so.1 (0x00007ffd447a0000)
libavcodec.so.58 => /usr/local/ffmpeg/libavcodec.so.58 (0x00007f5673121000)
libavformat.so.58 => /usr/local/ffmpeg/libavformat.so.58 (0x00007f5672cdb000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5671ffb000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5671de3000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f56719f2000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5671654000)
/lib64/ld-linux-x86-64.so.2 (0x00007f567629b000)
libswresample.so.3 => not found
libavutil.so.56 => not found
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5671435000)
libavutil.so.56 => not found
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5671231000)
while in my make --trace the library is present
/usr/bin/c++ -I/home/arunabh-compute/sensor-drivers -isystem
/usr/local/include -isystem /usr/local/GenICam/include -Wall -O3 -
std=gnu++14 -o CMakeFiles/save_cpp.dir/stdafx.cpp.o -c /home/arunabh-
compute/sensor-drivers/stdafx.cpp
CMakeFiles/save_cpp.dir/build.make:178: update target 'save_cpp' due
to: CMakeFiles/save_cpp.dir/link.txt
CMakeFiles/save_cpp.dir/Cpp_Save.cpp.o
CMakeFiles/save_cpp.dir/stdafx.cpp.o
CMakeFiles/save_cpp.dir/build.make /usr/local/ffmpeg/libavcodec.so
/usr/local/ffmpeg/libavcodec.so.58
/usr/local/ffmpeg/libavcodec.so.58.18.100
/usr/local/ffmpeg/libavdevice.so /usr/local/ffmpeg/libavdevice.so.58
/usr/local/ffmpeg/libavdevice.so.58.3.100
/usr/local/ffmpeg/libavfilter.so /usr/local/ffmpeg/libavfilter.so.7
/usr/local/ffmpeg/libavfilter.so.7.16.100
/usr/local/ffmpeg/libavformat.so /usr/local/ffmpeg/libavformat.so.58
/usr/local/ffmpeg/libavformat.so.58.12.100
/usr/local/ffmpeg/libavutil.so /usr/local/ffmpeg/libavutil.so.56
/usr/local/ffmpeg/libavutil.so.56.14.100
/usr/local/ffmpeg/libswresample.so
/usr/local/ffmpeg/libswresample.so.3
/usr/local/ffmpeg/libswresample.so.3.1.100
/usr/local/ffmpeg/libswscale.so /usr/local/ffmpeg/libswscale.so.5
/usr/local/ffmpeg/libswscale.so.5.1.100
even though libswresample.so.3, libavutil.so.56 is clearly present in the make --trace the application doesn't link to it for some reason, additionally if i put the /usr/local/ffmpeg folder in my LD_LIBRARY_PATH everything starts working just fine. Additionally libavcodec.so.58 is found. Trying to understand what's happening and how to fix it. Thanks.
By linking with these libraries, you marked them as needed in your binary, without recording any paths.
By default, your system only looks for dynamic libraries in a handful of locations.
You have a few options:
Add /usr/local/ffmpeg to a file in /etc/ld.so.conf.d/ (don't forget to call ldconfig). This will tell your dynamic linker (ld.so) to look there.
Add /usr/local/ffmpeg to the LD_LIBRARY_PATH environment variable as you did. You can make this permanent by editing /etc/environment on some machines. This has the same effect, but can be overridden by users. Most games on Linux rely on this to find the bundled libraries, for example, but this does necessitate a launcher script.
Link your binary with -rpath=/usr/local/ffmpeg. This informs the dynamic linker that you would like it to look there too. You can do this in CMake by setting the INSTALL_RPATH target property. You probably want to set BUILD_WITH_INSTALL_RPATH as well, so you do not have to set LD_LIBRARY_PATH during development or set a separate BUILD_RPATH.
Finally, you can just move the ffmpeg libraries to a directory in the default search path. However, this may clash with system libraries and requires root access. This is more a last-resort or convenience-over-everything approach.

error while loading shared libraries: libQt5Multimedia.so.5: cannot open shared object file: No such file or directory

I have a 32-bit linux Virtual Box which I am compiling my Qt c++ code on.
I am copying the target files to a 64-bit linux box (the 32-bit executable should still run on this PC).
The build is using dynamic linking, so I was going to start copying across the Qt lib files that I need. I planned to just do this manually by running the program and letting it tell me which lib files are missing + I know many of the files that I need so it won't take me long (normally).
So in my 64-bit box target folder I have the files:
Rpe
So I run my executable called "Rpe" and it complains:
./Rpe: error while loading shared libraries: libQt5Multimedia.so.5: cannot open shared object file: No such file or directory
I expected this to happen, then I go and copy the file libQt5Multimedia.so.5 from my 32-bit linux qt lib folder into the target directory on my 64-bit linux box. In my target folder I now have the files:
Rpe
libQt5Multimedia.so.5
I now run the Rpe executable again and I expect it to complain about a different lib file, however it is still complaining about the same libQt5Multimedia.so.5 file not being found.
What am I doing wrong here?
EDIT-1
LDD output:
adadacha#duanedibbley:~/sandbox$ ldd Rpe
linux-gate.so.1 => (0xf7731000)
libQt5Multimedia.so.5 => not found
libQt5Network.so.5 => not found
libQt5Xml.so.5 => not found
libQt5Core.so.5 => not found
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xf7616000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xf75f9000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf744a000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xf7404000)
/lib/ld-linux.so.2 (0x5661f000)
adadacha#duanedibbley:~/sandbox$
I would create a directory for your "product" with the executable in a bin sub-directory and the Qt libraries (and any other libraries) in a lib sub-directory.
In the parent directory I would add a wrapper script to set $LD_LIBRARY_PATH and execute the binary (not tested):
#!/bin/sh
dirname="$(dirname "$0")"
exename="$(basename "$0")"
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$dirname/lib"
export LD_LIBRARY_PATH
exec "$dirname/bin/$exename" $*

Conflicting boost versions

I have compiled boost::system and boost::serialization from with the older GCC ABI (https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html) due to some older third-party code I'm using.
I had them built to /usr/local/lib which is already set as a valid path to the linker (I use other libraries there as well), and renamed them to:
$ ls /usr/local/lib/libboost_*
/usr/local/lib/libboost_serialization_old_abi.so
/usr/local/lib/libboost_serialization_old_abi.so.1.60.0
/usr/local/lib/libboost_system_old_abi.so
/usr/local/lib/libboost_system_old_abi.so.1.60.0
/usr/local/lib/libboost_wserialization_old_abi.so
/usr/local/lib/libboost_wserialization_old_abi.so.1.60.0
Default, mainstream boost libraries are under /usr/lib as usual. What happens is that when I link any piece of code to these specific libraries with the custom flags -lboost_system_old_abi and -lboost_serialization_old_abi, the resulting binary will be linked to the default boost libraries:
$ ldd darwin_socket
linux-vdso.so.1 (0x00007ffd137ea000)
/usr/local/webots/resources/projects/robots/darwin-op/libraries/darwin/libdarwin.so (0x00007fcb9edaa000)
libipsocket.so.1 => /usr/local/lib/libipsocket.so.1 (0x00007fcb9eb7b000)
libboost_system.so.1.60.0 => /usr/lib/libboost_system.so.1.60.0 (0x00007fcb9e977000)
libboost_serialization.so.1.60.0 => /usr/lib/libboost_serialization.so.1.60.0 (0x00007fcb9e739000)
libController.so => not found
libCppController.so => not found
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fcb9e3b7000)
libm.so.6 => /usr/lib/libm.so.6 (0x00007fcb9e0b2000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007fcb9de9c000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007fcb9dafb000)
/lib64/ld-linux-x86-64.so.2 (0x00007fcb9efc1000)
librt.so.1 => /usr/lib/librt.so.1 (0x00007fcb9d8f3000)
libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007fcb9d6d6000)
which is quite strange, because, if use original -lboost_system and -lboost_serialization flags, gcc can't even link to the default boost due to new/old ABI incompatibilities.
So what exactly is happening here?
The problem is that just renaming your custom built libraries is not enough. The library name is embedded into the library as soname (you can see it with the readelf -d command) and is used when your application is liked with the library. Basically, the sonames from the custom libraries are put as the dependencies into your application binary, and since they are the same as the official Boost library names, the wrong binaries are loaded in run time.
You have to make sure the custom built Boost libraries are properly named in the build process. You can try doing this by adding --buildid=old_abi option to your b2 command line.

Error when using python to wrap up my c++ code into *.so file

I have a small project wrote in c++, and now I am going to build it into *.so file.
it works fine in the building process, no errors and generate the *.so I want.
file I use for building *.so file
module1 = Extension('classmod',
include_dirs=['/usr/lib/python2.7/dist-packages/numpy/','/home/******/OpenCV/opencv/release/include','/home/******/OpenCV/opencv/release/include/opencv','/home/******/OpenCV/opencv/release/include/opencv2','/home/******/modulepipe/eigen-eigen-b23437e61a07'],
library_dirs=['/usr/local/lib/'],
libraries=['opencv_calib3d','opencv_contrib','opencv_core','opencv_features2d','opencv_flann','opencv_gpu',
'opencv_highgui','opencv_imgproc','opencv_legacy','opencv_ml','opencv_nonfree','opencv_objdetect',
'opencv_photo','opencv_stitching','opencv_superres','opencv_ts','opencv_video','opencv_videostab'],
sources=['classmodule.cpp','patch_match.cpp','compute_jaccard.cpp','find_diff.cpp','refine_match.cpp','tps.cpp','book_pipeline_single.cpp','imgfeatures.c','kdtree.c','minpq.c','sift.c','utils.c'],
language='c++',
extra_compile_args=['-O3'])
setup(name='classmod',
version='1.0',
description='blah',
author='blah',
url='blah',
ext_modules=[module1]
)
However when I am trying to load this .so lib use lbb, it tells me about can not find several opencv *.so lib.
command I use for testing:
~/CDH/modulepipe$ ldd classmod.so
linux-gate.so.1 => (0xb77b4000)
libopencv_calib3d.so.2.4 => not found
libopencv_core.so.2.4 => not found
libopencv_features2d.so.2.4 => not found
libopencv_highgui.so.2.4 => not found
libopencv_imgproc.so.2.4 => not found
libopencv_nonfree.so.2.4 => not found
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb7690000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb7663000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb7645000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb762a000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7480000)
/lib/ld-linux.so.2 (0xb77b5000)
This is the problem I have. Can anyone help me on explaining this?
I had this "lib not found problem" before, and it was in the build phase. But in this case, in the building process it passed, which means ldd could find *.so's it needed. So how it happens that, when I am trying to run "ldd classmod.so", it could not find the *.so's.
Your loader can't find those shared objects. Either place them somewhere the loader expects to find them, modify the loader configuration (man 8 ldconfig) to look for shared objects where they are, or use one of the loader's environment variables (man 8 ld.so) to specify where to look for them.

Qt program does not detect libraries

I built a Qt application and included the necessary libraries needed in the build directory. When I try to run the application from a different computer, it doesn't work.
This is the ldd output:
linux-vdso.so.1 => (0x00007fff8c7fe000)
libQt5Widgets.so.5 => not found
libQt5Gui.so.5 => not found
libQt5Core.so.5 => not found
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5cb4143000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5cb3f2d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5cb3b6c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5cb3870000)
/lib64/ld-linux-x86-64.so.2 (0x00007f5cb4456000)
The files not found are in the same directory as the binary. How do I make them detectable?
On Linux current binary directiry is not the place where the loader looks for shared libraries. See this question: https://serverfault.com/questions/279068/cant-find-so-in-the-same-directory-as-the-executable
You can add the following to your .pro file to force the dynamic linker to look in the same directory as your Qt application at runtime in Linux :
unix:{
# suppress the default RPATH if you wish
QMAKE_LFLAGS_RPATH=
# add your own with quoting gyrations to make sure $ORIGIN gets to the command line unexpanded
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'"
}