我该如何修复此错误:找不到 -lglfw3 (Open Gl)

我该如何修复此错误:找不到 -lglfw3 (Open Gl)

make我在执行命令时遇到此错误

/usr/bin/ld: cannot find -lglfw3
collect2: error: ld returned 1 exit status
CMakeFiles/wrapmodes.dir/build.make:95: recipe for target '../bin/wrapmodes' failed
make[2]:  [../bin/wrapmodes] Error 1
CMakeFiles/Makefile2:99: recipe for target 'CMakeFiles/wrapmodes.dir/all' failed
make[1]:  [CMakeFiles/wrapmodes.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make:  [all] Error 2

答案1

尝试将链接更改为glfw而不是glfw3

当我尝试从 Windows 设置构建 Code::Blocks 项目时遇到同样的问题时,该解决方案对我有用。此外,我认为您还必须链接到GL而不是openglopengl32(不确定这是否适用于您)。

答案2

对于 openGL SuperBible,当我cmake从构建目录运行时:

cmake ..
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) at /home/michael/.local/lib/python3.8/site-packages/cmake/data/share/cmake-3.24/Modules/FindOpenGL.cmake:315 (message):
  Policy CMP0072 is not set: FindOpenGL prefers GLVND by default when                                                                                               
  available.  Run "cmake --help-policy CMP0072" for policy details.  Use the                                                                                        
  cmake_policy command to set the policy and suppress this warning.                                                                                                 

  FindOpenGL found both a legacy GL library:                                                                                                                        

    OPENGL_gl_LIBRARY: /usr/lib/x86_64-linux-gnu/libGL.so                                                                                                           

  and GLVND libraries for OpenGL and GLX:                                                                                                                           

    OPENGL_opengl_LIBRARY: /usr/lib/x86_64-linux-gnu/libOpenGL.so                                                                                                   
    OPENGL_glx_LIBRARY: /usr/lib/x86_64-linux-gnu/libGLX.so                                                                                                         

  OpenGL_GL_PREFERENCE has not been set to "GLVND" or "LEGACY", so for                                                                                              
  compatibility with CMake 3.10 and below the legacy GL library will be used.                                                                                       
Call Stack (most recent call first):                                                                                                                                
  CMakeLists.txt:19 (find_package)                                                                                                                                  
This warning is for project developers.  Use -Wno-dev to suppress it.                                                                                               

-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so   
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Checking for module 'glfw3'
--   Found glfw3, version 3.3.2
-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP_CXX: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5")  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/michael/Documents/OpenGL/SuperBible/sb7code-master/build
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

当我跑步时make

make
Consolidate compiler generated dependencies of target sb7
[  5%] Built target sb7
Consolidate compiler generated dependencies of target alienrain
[  6%] Linking CXX executable /home/michael/Documents/OpenGL/SuperBible/sb7code-master/bin/alienrain
/usr/bin/ld: cannot find -lglfw3
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/alienrain.dir/build.make:98: /home/michael/Documents/OpenGL/SuperBible/sb7code-master/bin/alienrain] Error 1
make[1]: *** [CMakeFiles/Makefile2:275: CMakeFiles/alienrain.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

系统从 cmke dump 中找到了 glfw3,所以我必须找到在 make 序列中使用 -lglfw3 的位置,因此我进入/OpenGL/SuperBible/sb7code-master/build/CMakeFiles/wrapmodes.dir/,由于这是一个链接错误,我单击了 link.txt 并得到了类似这样的内容:

/usr/bin/c++  -fopenmp -D_LINUX -std=c++0x -rdynamic CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o -o /home/michael/Documents/OpenGL/SuperBible/sb7code-master/bin/wrapmodes   -L/home/michael/Documents/OpenGL/SuperBible/sb7code-master/lib  -Wl,-rpath,/home/michael/Documents/OpenGL/SuperBible/sb7code-master/lib lib/libsb7.a -lglfw3 -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -lGL -lrt -ldl 

我将所有文件夹和 link.txt 文件的 -lglfw3 替换为 -lglfw,然后运行make所有文件 make-d/built。

我必须将媒体文件复制到其中/bin/media

当我进入 bin 文件夹并单击depthclamp时,我得到了一个正在运行的程序!我快速浏览了文件/二进制文件,并运行了几个带有着色器和纹理的程序,发现它们运行了。

相关内容