libRmath.so: cannot open shared object file: No such file or directory

% locate Rmath
/m/backup/backup/lib/R/include/Rmath.h
/usr/lib/R/include/Rmath.h
% gcc -g -o stand stand.c -I/usr/lib/R/include/ -lRmath -lm
% ./stand
./stand: error while loading shared libraries: libRmath.so: cannot open shared object file: No such file or directory

What's the trouble and how to remove it ?

Regards

The trouble is much like it says -- it can't find libRmath.so. It usually searches in /lib/ and /usr/lib, can you find it on your system?

It is found in /usr/lib/, compiled but can not run

% gcc -g -o stand stand.c -I/usr/lib/ -lRmath -lm
% ./stand
./stand: error while loading shared libraries: libRmath.so: cannot open shared object file: No such file or directory

Is there some trick in '-I/usr/lib/' ?

Check whether your LD_LIBRARY_PATH variable is correctly set.

Is there any solution else? I am advised to avoid LD_LIBRARY_PATH. Can other methods be available?

Thanks

LD_LIBRARY_PATH is a security risk when set to directories that can be easily modified, but I don't see harm in setting it to /usr/lib/. I'm more curious whether LD_LIBRARY_PATH even works; if it still doesn't load, the library may be corrupted or incompatible for some reason. You could also try running /sbin/ldconfig as root in case that library's not cached yet for some reason.

LD_LIBRARY_PATH can work. But it is useful to remind that the library may be corrupted or incompatible
Thanks