为什么会得到:“对`glfwInit'的未定义引用”?

时间:2018-12-28 14:37:32

标签: glfw autotools configure automake msys2

每当我尝试通过 MSYS2 Autotools 然后通过make静态编译的 GLEW GLFW ),我得到的是这种输出:

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 获得相同的结果。

1 个答案:

答案 0 :(得分:2)

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