共享库加载错误(glew)

7

我编译了GLEW库。看起来一切都正常,这是make install的输出:

install -d -m 0755 "/usr/include/GL"
install -m 0644 include/GL/wglew.h "/usr/include/GL/"
install -m 0644 include/GL/glew.h "/usr/include/GL/"
install -m 0644 include/GL/glxew.h "/usr/include/GL/"
sed \
        -e "s|@prefix@|/usr|g" \
        -e "s|@libdir@|/usr/lib64|g" \
        -e "s|@exec_prefix@|/usr/bin|g" \
        -e "s|@includedir@|/usr/include/GL|g" \
        -e "s|@version@|1.11.0|g" \
        -e "s|@cflags@||g" \
        -e "s|@libname@|GLEW|g" \
        -e "s|@requireslib@|glu|g" \
        < glew.pc.in > glew.pc
install -d -m 0755 "/usr/lib64"
install -m 0644 lib/libGLEW.so.1.11.0 "/usr/lib64/"
ln -sf libGLEW.so.1.11.0 "/usr/lib64/libGLEW.so.1.11"
ln -sf libGLEW.so.1.11.0 "/usr/lib64/libGLEW.so"
install -m 0644 lib/libGLEW.a "/usr/lib64/"
install -d -m 0755 "/usr/lib64"
install -d -m 0755 "/usr/lib64/pkgconfig"
install -m 0644 glew.pc "/usr/lib64/pkgconfig/"

现在我想在KDevelop项目中使用它。我创建了CMakeLists.txt,并使用find_package链接库:

cmake_minimum_required( VERSION 2.6 )

project(openglengine)

include_directories(headers)

set(SOURCE_FILES src/main.cpp)

set(CMAKE_CXX_FLAGS "--pedantic-errors -Wall -std=gnu++11")
add_executable(openglengine ${SOURCE_FILES} ${HEADER_FILES})

find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
target_link_libraries(openglengine ${GLFW_STATIC_LIBRARIES})

find_package(GLEW)
if (GLEW_FOUND)
    include_directories(${GLEW_INCLUDE_DIRS})
    target_link_libraries (openglengine ${GLEW_LIBRARIES})
endif (GLEW_FOUND)

install(TARGETS openglengine RUNTIME DESTINATION ~/projects/OpenGLEngine/bin)

我没有收到任何构建错误。 当我尝试运行程序时,这是输出结果:

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

任何帮助都将不胜感激。
编辑:
使用命令 locate libGLEW,我得到以下输出:
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu/libGLEW.so.1.10
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu/libGLEW.so.1.10.0
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu/libGLEW.so.1.6
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu/libGLEW.so.1.6.0
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu/libGLEW.so.1.10
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu/libGLEW.so.1.10.0
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu/libGLEW.so.1.6
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu/libGLEW.so.1.6.0
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEW.a
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEW.so
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEW.so.1.11
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEW.so.1.11.0
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEWmx.a
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEWmx.so
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEWmx.so.1.11
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEWmx.so.1.11.0
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEW.a
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEW.so
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEW.so.1.11
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEW.so.1.11.0
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEWmx.a
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEWmx.so
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEWmx.so.1.11
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEWmx.so.1.11.0
/usr/lib64/libGLEW.a
/usr/lib64/libGLEW.so  
/usr/lib64/libGLEW.so.1.11
/usr/lib64/libGLEW.so.1.11.0

这表明我已经有了该库。这是否意味着find_package命令可能不起作用?这很奇怪,因为我没有得到链接错误。


你是否将/usr/local/lib添加到了/etc/ld.so.conf中并运行了ldconfig?或者使用一些-Wl,-rpath选项链接你的程序? - Basile Starynkevitch
@BasileStarynkevitch 我没有做任何这样的事情,难道我应该吗?我所做的只是上面发布的 CMakeLists 和 glew 的编译,就是输入 glew 并执行 make 和 make install。 - lhahn
2个回答

15

所以,我通过在/usr/lib/中创建一个符号链接,使得位于/usr/lib64中的库文件成功工作。

sudo ln -s /usr/lib64/libGLEW.so.1.11 /usr/lib/libGLEW.so.1.11

现在它工作得很好。由于我不是Linux专家,我不知道这是否会给我带来未来的问题。


我没有安装这个库,有人能提供安装指南吗? - Anurag Daware
对我有用!! - Shubham
@AnuragDaware 您可以按照此指南 http://glew.sourceforge.net/install.html 进行安装。 - Shubham
@ShubhamDharma - 谢谢,我会试一下。 - Anurag Daware
我认为错误发生的原因是没有定义GLEW_STATIC。[https://dev59.com/rarka4cB1Zd3GeqPeXts] - Vishal Dalwadi

1

我不知道@Ihahn的答案是否存在任何问题,但如果某个程序找不到您的共享库,则首先找到安装您的库的文件夹并不在您的共享库文件夹中,然后运行sudo ldconfig <location_where_your_library_or_program_was_installed>。有时这种情况发生在通过make install安装/构建程序时。参考文献在此处。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接