加载共享库时出错(glew)

时间:2014-10-14 23:58:16

标签: linux makefile cmake shared-libraries glew

我编译了库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可能无法正常工作?这很奇怪,因为我没有链接错误。

2 个答案:

答案 0 :(得分:12)

因此,我设法通过在/ usr / lib /中为/ usr / lib64中的库创建符号链接来使其工作。

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

现在它运作正常。由于我不是Linux专家,我不知道这是否会给我带来问题。

答案 1 :(得分:0)

我不知道@Ihahn的答案是否有任何问题,但是,如果某个程序未找到您的共享库,则首先找到您的库已安装且不在共享库文件夹中的文件夹,然后然后运行sudo ldconfig <location_where_your_library_or_program_was_installed>。有时,当您通过make installReference here.安装/构建程序时,会发生这种情况。