How can I get better error messages when developing shared libraries with ubuntu?
I'm developing a few shared objects to be loaded by our framework due to my inability to make everything 100% proof, sometimes external dependencies are added, which cannot be found when the library is loaded at runtime.
The error message for such things is something like: Cannot open shared object file: File or directory not found. What it REALLY is saying that something failed while loading the file.
Is there any way to make gdb spit out what actually was missing?
I used ldd to see if anything big was missing, but it said that everything is found.
Related
I'm sorry about the vagueness of this post, but I'm not able to share the code, and anyway, it would be too much to share anyway.
I have this shared library, "shared", which is loaded by another library. The problem is that when loading the shared library, I get the error message saying "undefined symbol: _ZplPKcRK18ExampleClass"
The problem I have is that ExampleClass is declared and defined in the shared library. I made sure that I the ExampleClass is properly defined, and that the .h and .cpp are actually getting compiled.
I'm really confused about this, so any insight would be really helpful.
I'm building using cmake 3.6.2 and gcc 4.8.5 on CentOS 7.
This is a problem that usually occurs when loading in a shared library and then trying to code from that library. Since linking of the library did not happen directly after compile time, you will not get any linker errors that would be associated with the file and what is dynamically loading it. Look into a demangler(c++filt) and try to get more information about what that "_ZplPKcRK18ExampleClass" references.
In my experience, it is usually something along the lines of a method signature mismatch and the code does not know where to branch after the library is loaded.
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.
Hello when I build my wxWidgets GUI application on Linux the build goes fine. I can even run it and it works as expected. When I copy the binary to another Ubuntu computer and try to run it I get this error:
./app2: error while loading shared libraries: libwx_baseu_unofficial-3.1.so.0: cannot open shared object file: No such file or directory
Even when copying the lib across I still get an issue. Why is it dependent on external libraries and how can I solve this problem as I don't want other computers to require this library to be installed? I suppose I could try to statically link it but others recommend you do not do this.
You need to install the entire wxWidgets runtime/shared library on any machine you copy your binary onto. This is the whole point of using aptitude -- each binary package has a list of dependencies that get installed along with it.
To overcome this you need to statically link your binary. You are currently using shared linking, which relies on, as you note, external libraries. ".so" means Shared Object. You'll have to link against static archive libraries, often ending in ".a". Typically development packages provided by aptitude do not provide these, so you will probably have to compile wxWidgets yourself to provide these. Just make sure to also statically link and compile all of wxWidgets downstream dependencies as well. This is the major downside of static linking.
You can also look into something like Holy Build Box.
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 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.