C++ g++;不';与GLFW的t链接
我正在尝试使用g++从glfw页面编译示例程序:C++ g++;不';与GLFW的t链接,c++,g++,glfw,C++,G++,Glfw,我正在尝试使用g++从glfw页面编译示例程序: #include <GLFW/glfw3.h> int main(void) { GLFWwindow* window; /* Initialize the library */ if (!glfwInit()) return -1; /* Create a windowed mode window and its OpenGL context */ window = gl
#include <GLFW/glfw3.h>
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
错误消息:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x17): undefined reference to `glfwInit'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x6a): undefined reference to `glfwCreateWindow'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x78): undefined reference to `glfwTerminate'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x8d): undefined reference to `glfwMakeContextCurrent'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x98): undefined reference to `glfwWindowShouldClose'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0xb1): undefined reference to `_imp__glClear@4'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0xc2): undefined reference to `_imp__glBegin@4'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0xdf): undefined reference to `_imp__glVertex2f@8'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0xf8): undefined reference to `_imp__glVertex2f@8'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x115): undefined reference to `_imp__glVertex2f@8'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x11f): undefined reference to `_imp__glEnd@0'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x12c): undefined reference to `glfwSwapBuffers'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x131): undefined reference to `glfwPollEvents'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x13b): undefined reference to `glfwTerminate'
collect2.exe: error: ld returned 1 exit status
我已经检查了多个来源,看看我是否链接错了,但对我来说,一切看起来都是对的
我的操作系统是Windows 10有时会有帮助,您能否准确地引用错误消息的示例
libglfw3.a
-->-lglfw3
?有时会有帮助,您能否准确地引用错误消息的示例libglfw3.a
-->-lglfw3
?
g++ -o sample.exe -LGLFW/lib-mingw-w64 sample.o libglfw3.a
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x17): undefined reference to `glfwInit'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x6a): undefined reference to `glfwCreateWindow'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x78): undefined reference to `glfwTerminate'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x8d): undefined reference to `glfwMakeContextCurrent'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x98): undefined reference to `glfwWindowShouldClose'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0xb1): undefined reference to `_imp__glClear@4'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0xc2): undefined reference to `_imp__glBegin@4'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0xdf): undefined reference to `_imp__glVertex2f@8'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0xf8): undefined reference to `_imp__glVertex2f@8'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x115): undefined reference to `_imp__glVertex2f@8'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x11f): undefined reference to `_imp__glEnd@0'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x12c): undefined reference to `glfwSwapBuffers'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x131): undefined reference to `glfwPollEvents'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x13b): undefined reference to `glfwTerminate'
collect2.exe: error: ld returned 1 exit status