Nav
Nav

Reputation: 20698

Freeglut program compiles but when run, shows the error: libglut.so.3: cannot open shared object file

This is my program:

#include </usr/local/include/GL/glut.h>

int main(int argc, char **argv) 
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowPosition(100,100);
    glutInitWindowSize(320,320);
    glutCreateWindow("Lighthouse3D- GLUT Tutorial");
}

Compiled with:

g++ -lglut -L/usr/local/lib/ -o start start.cpp;./start

Error shown:

./start: error while loading shared libraries: libglut.so.3: cannot open shared object file: No such file or directory

The file is present.

bashprompt> locate libglut.so.3
/usr/local/lib/libglut.so.3
/usr/local/lib/libglut.so.3.9.0

Had also tried:

LD_RUN_PATH="/usr/local/lib/"
g++ -lglut -LLIBDIR -o start start.cpp;./start with no luck.

These were the messages shown while installing (if this helps):

root@Nav:/home/Nav/freeglut-2.6.0# make install Making install in src
make[1]: Entering directory /home/Nav/freeglut-2.6.0/src'
make[2]: Entering directory
/home/Nav/freeglut-2.6.0/src' test -z "/usr/local/lib" || /bin/mkdir -p "/usr/local/lib" /bin/sh ../libtool --mode=install /usr/bin/install -c 'libglut.la' '/usr/local/lib/libglut.la'
/usr/bin/install -c .libs/libglut.so.3.9.0 /usr/local/lib/libglut.so.3.9.0 (cd /usr/local/lib && { ln -s -f libglut.so.3.9.0 libglut.so.3 || { rm -f libglut.so.3 && ln -s libglut.so.3.9.0 libglut.so.3; }; })
(cd /usr/local/lib && { ln -s -f libglut.so.3.9.0 libglut.so || { rm -f libglut.so && ln -s libglut.so.3.9.0 libglut.so; }; }) /usr/bin/install -c .libs/libglut.lai /usr/local/lib/libglut.la
/usr/bin/install -c .libs/libglut.a /usr/local/lib/libglut.a chmod 644 /usr/local/lib/libglut.a ranlib /usr/local/lib/libglut.a
PATH="$PATH:/sbin" ldconfig -n /usr/local/lib
---------------------------------------------------------------------- Libraries have been installed in:
/usr/local/lib If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the -LLIBDIR' flag during linking and do at least one of the following:
- add LIBDIR to the
LD_LIBRARY_PATH' environment variable during execution
- add LIBDIR to the LD_RUN_PATH' environment variable during linking
- use the
-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages.

Upvotes: 1

Views: 6770

Answers (1)

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81724

Your LD_RUN_PATH attempt was very close, but it should be LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=/usr/local/lib
./start

This tip from the installer is also handy:

have your system administrator add LIBDIR to `/etc/ld.so.conf'

If you did that, you wouldn't need to do the LD_LIBRARY_PATH thing.

Upvotes: 3

Related Questions