为什么我得到:"undefined reference to `glfwInit'"?

Why am I getting: "undefined reference to `glfwInit'"?

每当我尝试通过 MSYS2Autotools 编译我的 OpenGL 示例项目,然后make使用静态编译的GLEWGLFW)我得到这种输出:

x86_64-w64-mingw32-g++ -DHAVE_CONFIG_H -I. -I./include  -I./include/GL -I./include/GLFW -DGLEW_STATIC   -g -O2 -MT src/opengl_tut-main.o -MD -MP -MF src/.deps/opengl_tut-main.Tpo -c -o src/opengl_tut-main.o `test -f 'src/main.cpp' || echo './'`src/main.cpp
mv -f src/.deps/opengl_tut-main.Tpo src/.deps/opengl_tut-main.Po
x86_64-w64-mingw32-g++  -g -O2 -L./lib -lglfw3 -lglew32 -lopengl32 -lgdi32  -o opengl_tut.exe src/opengl_tut-main.o
src/opengl_tut-main.o: In function `main':
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:13: undefined reference to `glfwInit'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:21: undefined reference to `glfwWindowHint'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:22: undefined reference to `glfwWindowHint'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:24: undefined reference to `glfwWindowHint'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:25: undefined reference to `glfwWindowHint'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:27: undefined reference to `glfwCreateWindow'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:41: undefined reference to `glfwGetFramebufferSize'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:45: undefined reference to `glfwMakeContextCurrent'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:49: undefined reference to `glewInit'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:58: undefined reference to `glViewport'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:62: undefined reference to `glfwPollEvents'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:64: undefined reference to `glClearColor'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:65: undefined reference to `glClear'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:67: undefined reference to `glfwSwapBuffers'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:60: undefined reference to `glfwWindowShouldClose'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:16: undefined reference to `glfwTerminate'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:52: undefined reference to `glfwDestroyWindow'
C:\Users\Test\Desktop\OpenGL_2/src/main.cpp:53: undefined reference to `glfwTerminate'
C:\Users\DoTestn\Desktop\OpenGL_2/src/main.cpp:35: undefined reference to `glfwTerminate'
src/opengl_tut-main.o:main.cpp:(.rdata$.refptr.glewExperimental[.refptr.glewExperimental]+0x0): undefined reference to `glewExperimental'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:361: opengl_tut.exe] Error 1  

我不明白的是,我可以使用如下所示的手动键入命令来编译我的代码:

x86_64-w64-mingw32-g++ -ggdb -Og -std=c++14 src/main.cpp -o bin/opengl_tut.exe -DGLEW_STATIC -I./include/GL -I./include/GLFW -L./lib -lglfw3 -lglew32 -lopengl32 -lgdi32  

但是,我更愿意使用 Autotools 获得相同的结果。

src/opengl_tut-main.o 对象可能依赖于 OpenGL 库,因此在将所有内容链接在一起的最终命令中,它必须列在 OpenGL 库之前。