3

I am trying to compile an opengl program which results in:

error while loading shared libraries: libGLEW.so.1.11: cannot open shared object file: No such file or directory

compile:

 g++ -o triangle triangle.cpp LoadShaders.cpp -I/home/mks/myGL/oglpg/include/ -L/home/mks/myGL/oglpg/lib  -L/usr/lib64 -lglut -lGL -lGLU -lGLEW

In /home/mks/myGL/oglpg/lib there are all the libraries:

 libGLEW.so       libGLEW.so.1.11.0  
 libGLEW.a    libGLEW.so.1.11  

( I am not superuser , so I installed glew on the above folder )

If I do:

ldd ./triangle | grep "GLEW"
        libGLEW.so.1.11 => not found

--UPDATE ---

Compiling:

g++ -o triangle triangle.cpp LoadShaders.cpp -I/home/mks/myGL/oglpg/include/ -L/home/mks/myGL/oglpg/lib -L/usr/lib64 -lglut -lGL -lGLU -lGLEW

ldd ./triangle :

linux-vdso.so.1 =>  
        libglut.so.3 => /usr/lib64/libglut.so.3 
        libGL.so.1 => /usr/lib64/nvidia/libGL.so.1 
        libGLU.so.1 => /usr/lib64/libGLU.so.1 
        libGLEW.so.1.11 => not found
        libstdc++.so.6 => /usr/lib64/libstdc++.so.6 
        libm.so.6 => /lib64/libm.so.6
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 
        libc.so.6 => /lib64/libc.so.6 
        libXext.so.6 => /usr/lib64/libXext.so.6 
        libX11.so.6 => /usr/lib64/libX11.so.6
        libXxf86vm.so.1 => /usr/lib64/libXxf86vm.so.1 
        libXi.so.6 => /usr/lib64/libXi.so.6 
        libnvidia-tls.so.340.29 => /usr/lib64/nvidia/tls/libnvidia-tls.so.340.29 
        libnvidia-glcore.so.340.29 => /usr/lib64/nvidia/libnvidia-glcore.so.340.29 
        libdl.so.2 => /lib64/libdl.so.2 
        /lib64/ld-linux-x86-64.so.2
        libxcb.so.1 => /usr/lib64/libxcb.so.1 
        libXau.so.6 => /usr/lib64/libXau.so.6 

ls -al /home/mks/myGL/oglpg/lib :

drwxr-xr-x.  .
drwxr-xr-x.  ..
-rw-r--r--.  freeglut_static.lib
-rw-r--r--.  freeglut_static_vs2010_d.lib
-rw-r--r--.  freeglut_static_vs2010.lib
-rw-r--r--.  gl3w.c
-rw-r--r--.  glew_static_d.lib
-rw-r--r--.  glew_static_vs2010_d.lib
-rw-r--r--.  glew_static_vs2010.lib
-rw-r--r--.  libfreeglut.a
-rw-r--r--.  libglew32.a
-rw-r--r--.  libGLEW.a
lrwxrwxrwx.  libGLEW.so -> libGLEW.so.1.11.0
lrwxrwxrwx.  libGLEW.so.1.11 -> libGLEW.so.1.11.0
-rw-r--r--.  libGLEW.so.1.11.0
-rw-r--r--.  LoadShaders.cpp
-rw-r--r--.  targa.cpp
-rw-r--r--.  vbm.cpp
-rw-r--r--.  vermilion32_d.lib
-rw-r--r--.  vermilion32.lib
-rw-r--r--.  vermilion64_d.lib
-rw-r--r--.  vermilion64.lib

echo $PATH:

/usr/local/cuda-6.0/bin:/home/mks/bin:/usr/local/cuda-6.0/bin:/usr/lib64/:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
  • This is not a compile-time problem, but a run-time problem, as @Gilles explained. You compiled the source code properly, now you need to point the run-time linker to the libraries that you linked against. – jayhendren Nov 4 '14 at 0:03
4

You need to instruct your system where to find dynamic libraries. System-wide directories like /usr/lib are in the default search path for dynamic libraries, but if you want to add custom directories, you need to declare them by listing them in the environment variable LD_LIBRARY_PATH. This is a colon-separated list of directories, like PATH.

export LD_LIBRARY_PATH=/home/mks/myGL/oglpg/lib

Put this line in your ~/.profile or wherever you define environment variables. You can also run it in a shell and it'll apply to all programs started from that shell.

Alternatively, when you build a program using the library, register its location on your system.

g++ -Wl,-rpath,/home/mks/myGL/oglpg/lib … -L /home/mks/myGL/oglpg/lib -lGLEW

The chapter on shared libraries in the Program Library Howto may be of additional help.

  • Using RPATH to link against external libraries (like you are doing in this case) may make the compiled binary less portable. I think using the LD_LIBRARY_PATH variable is the better solution in this case. – jayhendren Nov 4 '14 at 0:01
  • @jayhendren A binary produced using RPATH and copied to another machine will only work if the library is at the same location on the other machine (or more precisely in one of the same set of locations). If it doesn't work, you'll have to use LD_LIBRARY_PATH on the other machine, which you'd have to do anyway. RPATH is only a problem when you have multiple versions of the same library in different directories, and you want to pick a particular one whose location is different on different machines. – Gilles Nov 4 '14 at 0:09
1

Update

Just noticed the superuser comment. You can still try the link command without being root. There is the chance that the permissions for that folder will still allow you. If it fails then you will need to contact your SysAdmin for help.


Where the application is looking for the library, the symlink doesn't exist.

Try this (while root):

ln -sf /home/mks/myGL/oglpg/lib/libGLEW.so.1.11.0 /usr/lib64/libGLEW.so.1.11

After that run ldd ./triangle again and see if the output finds the symlink. If it doesn't look at the locations it is looking for the other symlinks and create a link there. If the location is not /usr/lib64 then make sure you unlink /usr/lib64/libGLEW.so.1.11 after you correct the symlink locations so you don't leave a unused symlink on your filesystem and forget to clean it up later.

ln => Create link

sf => symlink, forced

  • :Unfortunatelly,the ln -sf doesn't work without being superuser.But ,I can't understand why it doesn't work since I have libGLEW.so.1.11 , and especially (libGLEW.so.1.11 -> libGLEW.so.1.11.0) in my home folder (/home/mks/myGL/oglpg/lib) – George Nov 3 '14 at 15:27
  • Because when 'triangle' was built, the path specified for libGLEW was something else (/usr/lib64?) and not the your path. If you can recompile 'triangle' and change the path, it should work. Where is triangle looking for the other paths? Show the full out put of ldd ./triangle without the grep please. – devnull Nov 3 '14 at 15:33
  • :Ok , I updated.the libGLEW is only in my home folder.I tried also compiling without /usr/lib64 – George Nov 3 '14 at 15:47
  • can you also provide the output of ls -al /home/mks/myGL/oglpg/lib to verify libGlew is linked properly in your build directory. Also the contents of PATH – eyoung100 Nov 3 '14 at 15:56
  • @eyoung100:Ok ,i updated – George Nov 3 '14 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.