0

I am building an application using OpenGL. I have multiple OpenGL installed on a server.

I noticed that even after specifying link path for OpenGL libraries at runtime in Makefile, when running the application it still looks for library in different places, resulting error.

The correct openGL path is /usr/lib/nvidia-410/

yuqiong@sturfee-dnn:~/sturgRender/assets$ ls  /usr/lib/nvidia-410/ | grep GL
libEGL_nvidia.so.0
libEGL_nvidia.so.410.129
libEGL.so
libEGL.so.1
libEGL.so.410.129
libGLdispatch.so.0
libGL.so
libGL.so.1
libGL.so.410.129
libGLX_indirect.so.0
libGLX_nvidia.so.0
libGLX_nvidia.so.410.129
libGLX.so
libGLX.so.0
libOpenGL.so
libOpenGL.so.0

However the LD_LIBRARY_PATH points to :

yuqiong@sturfee-dnn:~/sturgRender/assets$ echo $LD_LIBRARY_PATH 
/usr/local/torch/lib:/usr/local/tensorrt/lib:/usr/local/caffe/lib/:/usr/local/lib;//usr/local/cuda/lib64:/home/yuqiong/TensorRT-7.0.0.11/lib

This will cause the application to result in eglDisplayError. However after changing LD_LIBRARY_PATH to /usr/lib/nvidia-410/, this error is gone.

I suspect this is because libEGL and libGLX and libOpenGL is dynamically loaded.

However, on another machine, I build the application using CMake, and even though LD_LIBRARY_PATH is empty the application still links the correct libraries.

  1. Why do I need to specify LD_LIBRARY_PATH on one machine but not the other?
  2. Is the information about where to load dynamic libraries stored in system variables like LD_LIBRARY_PATH, or in the application itself?
genpfault
  • 51,148
  • 11
  • 85
  • 139
yuqli
  • 4,461
  • 8
  • 26
  • 46
  • Someone edited before I could comment, but just a friendly reminder for future reference: Asking for off-site resources is explicitly [off-topic](https://stackoverflow.com/help/on-topic). Please try to avoid that in the future. –  Aug 17 '20 at 03:48
  • @Chipster sure. Thanks for the helpful comment! – yuqli Aug 17 '20 at 03:51

1 Answers1

2

You need to understand what is rpath, what is library search path and the rules for searching libraries.

For rpath and library search path, please check this one:

What's the difference between -rpath and -L?

For the rules for searching libraries, please check this one:

https://unix.stackexchange.com/questions/22926/where-do-executables-look-for-shared-objects-at-runtime

The makefile based build apparently does not uses rpath therefore based on the search order, loader finds the libraries in some other folder and it causes the issue. The cmake based build system either uses rpath or library is installed in default folders that loader checks regardless of settings.

I do not want to repeat what is already explained in other answers. I am merely trying to direct you to correct path to read more and understand these settings, then it will be obvious why you experience the issue and how to solve it.

Validus Oculus
  • 2,756
  • 1
  • 25
  • 34
  • 1
    Yes this is exactly what I need to know ! Thanks for the redirection. It's very helpful. – yuqli Aug 17 '20 at 05:45