My application uses the Sun N1 grid engine through the API DRMAA present as shared object libdrmaa.so
.
I am using dlopen and dlsym to acess functions of the library. That works fine. Now if I try to link
it form command line the executable is built but executing it gives the error " Cannot open shared object file".
Can anyone suggest what may be the reason.
I am using g++ 2.95.3 for compilation and the machine is linux x86_64.
Thanx
Your question and answer are both very confused: if you can link your executable directly against libdrmaa.so, then there is absolutely no good reason to also dlopen that same library (and presumably call dlsym() on its handle as well).
Related
I'm reciving a very odd error. I'm compiling a code which parses JSON data from a url using libcurl. After trial and error I've gotten it compiled without error. However, when trying to run the code I get a system error, saying libcurl-x64.dll was not found.
Picture of error here
I'm not exactly sure what is finding what, here. My windows system cannot find libcurl-x64.dll or is it my gcc compiler? Nevertheless, a quick system search shows the location of it. I didn't use it for anything. What exactly do I need to do with libcurl-x64.dll so that my system can find it? It only pertains to this one parsing program I'm doing, every other cpp/exe file and project works fine. System specs: Windows 10, Dev C++ IDE, mingw g++ compiler.
Here is the location of my supposedly missing file:
FilePath1
FilePath2
The search order of DLLs for desktop Windows applications is as follows:
The directory from which the application loaded.
The system directory. (e.g. \Windows\System32 or \Windows\SysWOW64)
The Windows directory. (e.g. \Windows)
The current directory.
The directories that are listed in the PATH environment variable.
You need to make sure the missing DLL is reachable via one of the above locations.
The best for a quick test is to copy it to the same location where your application (.exe) is located.
It has nothing to do with your compiler. On any OS that supports dynamic
libaries (DLLs on Windows, shared libraries on Linux, etc.), if a program has
been linked to some dynamic library at linktime then, at runtime, the OS
program loader must be able to find that dynamic library in
one of the places where it looks for dynamic libraries by default, or in one
of the places that you specify at runtime in some OS-dependent manner.
This is the nature of dynamic libraries.
In the case of Windows, it means that to run a program you have linked with
libcurl-x64.dll the program loader will try to locate libcurl-x64.dll
using the Search Path Used by Windows to Locate a DLL,
in order to load it into your program's process. If it fails to find libcurl-x64.dll in any of those places
then the program will fail to start, with the error you observed.
I have some C++ code in place, which internally uses multiple third party libraries. The code compiles fine but during execution it is failing to load some shared library(libintbasic.so). Given the condition, I can not install any library into the system, the only way out is to find which function is calling that library. How could I find that out who is calling that library (my code does not call that directly).
I can not install any library into the system,
That appears to be a bogus claim: clearly you can copy your binary onto the system. Installing an additional library into the same directory is not much harder.
How could I find that out who is calling that library
There are two cases to consider:
your binary or one of the libraries it is directly linked with links to libintbasic.so. Your binary will not run at all, or
your binary, or one of the libraries it is directly linked with calls dlopen("libintbasic.so",...) and fails when that dlopen fails.
Debugging the first case is often easiest by setting LD_DEBUG=files,libs. The dynamic loader will then tell you which libraries are being loaded, and why they are required.
Debugging the second case is easy with gdb: set a breakpoint on dlopen, and execute where and info shared commands every time the breakpoint is hit.
Remove the linking option -lintbasic, you will see all the functions that needs this library in the error messages. This is not clean but it should work fine.
You may use ldd utility recursively for find all dependencies between shared libraries.
The following link also may be useful: Does ldd also show dependencies of dependencies?
I have shared library code in c++ . I am replacing the existing c++ shared library with newer one with changes in c++ functions. But the application is not executing the latest code path instead it goes through the previous code path i.e I have added a print with additional messages in the newer library but the print that I get is from previous one.
I have used strings command to check the changes are reflected in the newer library and it is giving positive result.
The application is using dynamic load call to open the library. I don't have the application code with me.
Make file has the following flags for creating shared library.
${CXX} -shared -Wl,--exclude-libs,ALL,-soname,${LIB} ${LDFLAGS} -o $# $(OBJECTS)
Is there any shared library flags that I am missing ?
Anyone has idea for this strange behaviour ?
PS:I am running this in a embedded environment.
I am assuming a few things here:
1. You have not linked your shared library with your executable with "-L" option. This would never unload your shared library.
2. The library is opened during run time using dlopen
Run time library swapping can work only if the mentioned 2 points hold true for you. When a shared library is opened (using dlopen) its loaded into program's memory. So, even if you delete the library from disk (after it has been loaded), the program will still continue to run whatsoever.
When you call dlclose it "decrements the reference count on the dynamic
library handle handle. If the reference count drops to zero and
no other loaded libraries use symbols in it, then the dynamic library
is unloaded."(From the man page)
So, what you should do to implement "refresh library mechanism" is to close the existing library with dlclose and reload your new library with dlopen (make sure that the symbol names are same for the new library as that of the old one) and the symbols accessed will be of new library.
So, such things must be supported within the program or end up using dirty hacks like LD_PRELOAD which will load your library upfront before the original library. But thats another thing which I think you are not looking for.
I upgraded my system (to ubuntu 13.04) and somewhere in the process gcc broke :-( I'm getting this exception when trying to compile something:
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/bin/as:
error while loading shared libraries:
libopcodes-2.22-system.so: cannot open shared object file: No such file or directory
Actually libopcodes-2.22-system.so does not exist, BUT libopcodes-2.23.2-system.so does.
If i symlink from 2.22 to 2.23 gcc fails with just another library.
So for some reason it is looking for the wrong version. I wildly tried to solve it by reinstalling gcc, binutils, libc6 etc., but the problem still exists.
How can i tell gcc to use the correct shared library version? / Where does gcc gets the information which shared libraries to use?
Thx
Thanks guys, your comments made me look at the right place.
This path made me suspicious:
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/bin/as
I thought it must be a symlink to /usr/bin/as, but it exposed that /usr/x86_64-linux-gnu/bin was a complete copy of /usr/bin - not up to date and therefore with incorrectly linked binaries. I have no idea why a copy of the whole bin directory was there and was used by gcc in favor of /usr/bin.
The compiler is running fine after /usr/x86_64-linux-gnu was removed.
Edit: Better check comments before doing the same.
I am building a unix c++ program that calls boost, but when i try to run it i get
error while loading shared libraries: libboost_filesystem.so.1.42.0: cannot open shared object file: No such file or directory.
I didn't use to get this error before ( even though i was already calling boost ) , though i don't know what triggered the change. Anyway - doing ldd on the binary, it indeed shows that the library is missing.
I guess the solution would be to add in the LD_LIBRARY_PATH a link to the library containing the .so file - but i can't find it. Where should it be? Is this the right solution?
Note that i don't have sudo privelages on my computer, so i can only change user settings - And also that i'm a linux newb so please try to explain simply...
I think the problem is that you have linked to a very specific version of Boost (1.42.0 in this case). This worked as long as Boost existed in that exact version on your system, but as soon as an update to a more recent version of Boost happened, the linked library could no longer be found.
You might want to adjust your Makefile to link to a more generic version of libboost_filesystem.so.