I have some weird memory related errors in my program.
It uses intel mkl and therefore depends upon some mkl specific shared libraries.
When I run my program, it segfaults after it has done most of the work. The segfaults occurs in the function call fclose() to a file pointer that is not null.
When I run my program through gdb, the stacktrace is not very useful.
I therefore wanted to run valgrind to find possible errors in my code.
But, I cannot run the executable from valgrind. It prints the following error message.
==52778== Memcheck, a memory error detector
==52778== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==52778== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==52778== Command: ./main.exe
./main.exe: error while loading shared libraries: libmkl_intel_lp64.so: cannot open shared object file: No such file or directory
The shared library libmkl_intel_lp64.so is present in the same directory (as well as all other shared libraries that my executable depends upon).
How do I resolve this problem, so that I can valgrind my code?
valgrind provides much of it's own environment and wrappers for various functions in order to do its job. Since you have set
LD_LIBRARY_PATH and are still experiencing problems finding your library, your other option is to provide the library search path within the executable itself using the linker option
-rpath=/path/to/dir that contains the library. The addition to the compile string would be:
-Wl,-rpath=/path/to/dir /* that has libmkl_intel_lp64.so in it */
Then finding the library doesn't depend on the external environment or the hope that
valgind will extend its library search to the current working directory.
(glad it worked)