2011-05-28 32 views
1

這是我的計劃:Freeglut程序編譯運行,但時,顯示了錯誤:libglut.so.3:無法打開共享對象文件

#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"); 
} 

與編譯:顯示

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

錯誤:

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

該文件存在。

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

還曾試圖:

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

這些是在安裝(如果這能幫助)顯示的信息:

[email protected]:/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.

回答

3

LD_RUN_PATH嘗試是非常接近,但它應該是LD_LIBRARY_PATH

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

這個技巧從安裝也很方便:

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

如果你這樣做,你就不需要做LD_LIBRARY_PATH事情。

+0

:)做到了!非常感謝! – Nav 2011-05-28 13:23:06

+1

您必須在'glutCreateWindow()'之後調用'glutMainLoop()',否則程序會在窗口出現之前退出。 – 2011-05-28 13:24:10

相關問題