Search code examples
c++clinuxlinkerdlopen

Why linker searches for a library in the path used for compiling in linux


I am building a shared library with option " -L/my/path/ -lxxx.so "

Now i am using dlopen to dynamically link this library to my application

pvHandle = dlopen (pszLibName, RTLD_LAZY | RTLD_GLOBAL);

But when i execute it is showing an error message /my/path/libxxx.so: cannot open shared object file: No such file or directory

libxxx.so is available in /usr/local/lib and i am appending this path to LD_LIBRARY_PATH

Any idea what i am doing wrong? Thanks in advance


Solution

  • Run ldconfig command. Also see man page of ldconfig command you can get idea about it.

    you need to add the path to the file /etc/ld.so.conf.

    OR

    give full path like

    dlopen("/some/path/to/lib.so",  RTLD_LAZY | RTLD_GLOBAL);