Question: I have an application a part of which uses shared libraries. These libraries are linked at compile time.

At Runtime the loader expects the shared object to be in the `LD_LIBRARY_PATH` , if not found the entire application crashes with error "unable to load shared libraries".Note that there is no guarantee that client would be having the library, in that case I want the application to leave a suitable error message also the independent part should work correctly.

For this purpose I am using `dlsym()` and `dlopen()` to use the API in the shared library. The problem with this is if I have a lot of functions in the API, i have to access them Individually using `dlsym()` and ptrs which in my case are leading to memory corruption and code crashes.

Are there any alternatives for this?

Answer: 
You can wrap your application with another one which first checks for all the required libraries, and if something is missing it errors out nicely, but if everything is allright it execs the real application.
You are probably looking for some form of delay library load on Linux. It's not available out-of-the-box but you can easily mimic it by creating a small static stub library that would try to `dlopen` needed library on first call to any of it's functions (emitting diagnostic message and terminating if `dlopen` failed) and then forwarding all calls to it.

Such stub libraries can be written by hand, generated by project/library-specific script or generated by universal tool [Implib.so](https://github.com/yugr/Implib.so):

```
$ implib-gen.py libxyz.so
$ gcc myapp.c libxyz.tramp.S libxyz.init.c ...

```