C++ program not linking to .so file properly

Viewed 633

I built GLEW (using make install) to use in a small test program I am writing (source can be found here if you need it). I ran locate libGLEW.so just to check if the GLEW libraries were properly installed, and got the following output:

/usr/lib64/libGLEW.so
/usr/lib64/libGLEW.so.2.0
/usr/lib64/libGLEW.so.2.0.0

This was completely normal. I then compiled it using the command:

g++ main.cpp -o main -lglfw -lGLEW -lGL -lX11 -lpthread -lXi -g

This also threw up no errors. However, when I tried to execute the program:

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

Just for a sanity check, I ran ldd main | grep "GLEW", and sure enough:

libGLEW.so.2.0 => not found

I initially thought that this could be a problem with the linker not searching the directory containing the libraries. So I ran the command ld --verbose | grep "/usr/lib64" and there was a SEARCH_DIR containing the required directory:

...  SEARCH_DIR("=/usr/lib64"); ...

This was especially confusing. I tried compiling with the -L/usr/lib64 option, but the same error message still persisted. I checked that the symlinks to the library were correct and they were:

lrwxrwxrwx  1 root root   16 Jul 15 10:22 libGLEW.so -> libGLEW.so.2.0.0
lrwxrwxrwx  1 root root   16 Jul 15 10:38 libGLEW.so.2.0 -> libGLEW.so.2.0.0
-rw-r--r--  1 root root 707K Jul 15 10:22 libGLEW.so.2.0.0

I am not sure what exactly is causing the issue but I'm starting to believe that I didn't install the libraries correctly. I feel like the answer is right in front of my eyes but I can't find it.

Thanks in advance for any help.

2 Answers
Related