Reputation: 31
I am new to c++ and have at my new project a problem I don't understand.
The relevant parts of my program are:
#include <glew.h>
#include <SDL.h>
#include <SDL_opengl.h>
int initGlew()
{
if(glewInit()!=GLEW_OK)
{
printf("Unable to init glew!");
return 1;
}
return 0;
}
But when I run it with codeblocks, there is the following runtime-error:
home/samuel/Dokumente/ProjekteC++/GameGL/bin/Debug/GameGL: error while loading shared libraries: libGLEW.so.1.9: cannot open shared object file: No such file or directory
At the build options i linked to these so-files:
I searched a lot where the error could be, but didn't found anything. I hope you can help me.
Upvotes: 3
Views: 7978
Reputation: 28325
Use of environment variable LD_LIBRARY_PATH is intended for a temporary, testing only solution. Instead, if on linux put same path into system wide config file :
/etc/ld.so.conf
like :
cat /etc/ld.so.conf
/usr/lib64
then to engage this change issue :
sudo ldconfig
Upvotes: 4
Reputation: 31
The error is saying that it cannot find a dynamic library at runtime. When you compile your application you link to static libraries (.a files) but at run time you can dynamically load .so files, that is what is happening here.
If you list your applications library dependencies you will probably see that it cannot find libGLEW. You can do this on the command line with the ldd command.
$ ldd <your_file>
linux-vdso.so.1 => (0x00007fff769ff000)
libGLEW.so.1.9 => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2af9e28000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2afa208000)
Adding directories to your library search path is done with the LD_LIBRARY_PATH export. Again you can do this on the command line like this.
$LD_LIBRARY_PATH=/usr/lib64 ldd <your_file>
linux-vdso.so.1 => (0x00007fff2e053000)
libGLEW.so.1.9 => /usr/lib64/libGLEW.so.1.9 (0x00007f4071ca5000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f40718c7000)
libGL.so.1 => /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 (0x00007f4071660000)
...
You can then run your app by omitting the ldd command. I'm not sure how to get this working in codeblocks but I'm assuming you can setup your debug environment configuration somewhere in the Run/Debug settings.
Thanks
Upvotes: 3