[英]GLFW link not working correctly with mingw32 in C++ (?)
Im trying to compile this example from the GLFW
webpage: 我正在尝试从GLFW
网页编译此示例:
http://www.glfw.org/documentation.html http://www.glfw.org/documentation.html
#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 */
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
Im using mingw32, and I downloaded the 32-bit windows binaries files from here http://www.glfw.org/download.html . 我使用的是mingw32,我从此处http://www.glfw.org/download.html下载了32位Windows二进制文件。
I put them in the respectives folders: 我把它们放在各自的文件夹中:
glfw3.dll
in C:\\Programming\\MinGW32\\bin
and a copy in my main.cpp
folder. C:\\Programming\\MinGW32\\bin
glfw3.dll
,我的main.cpp
文件夹中的副本。
glfw3dll.a
and libglfw3.a
in C:\\Programming\\MinGW32\\lib
C:\\Programming\\MinGW32\\lib
glfw3dll.a
和libglfw3.a
GLFW folder
with its .h files in C:\\Programming\\MinGW32\\include
GLFW folder
及其.h文件位于C:\\Programming\\MinGW32\\include
To compile all I use this: g++ -lglfw3dll -lopengl32 main.cpp -Wall -o main.exe
要编译所有文件,请使用以下代码: g++ -lglfw3dll -lopengl32 main.cpp -Wall -o main.exe
And this are the errors Im getting: 这是我得到的错误:
D:\Users\Jorge\AppData\Local\Temp\ccA4Wc7r.o:animation.cpp:(.text+0xf): undefined reference to `glfwInit'
D:\Users\Jorge\AppData\Local\Temp\ccA4Wc7r.o:animation.cpp:(.text+0x4e): undefined reference to `glfwCreateWindow'
D:\Users\Jorge\AppData\Local\Temp\ccA4Wc7r.o:animation.cpp:(.text+0x5e): undefined reference to `glfwTerminate'
D:\Users\Jorge\AppData\Local\Temp\ccA4Wc7r.o:animation.cpp:(.text+0x71): undefined reference to `glfwMakeContextCurrent'
D:\Users\Jorge\AppData\Local\Temp\ccA4Wc7r.o:animation.cpp:(.text+0x7f): undefined reference to `glfwSwapBuffers'
D:\Users\Jorge\AppData\Local\Temp\ccA4Wc7r.o:animation.cpp:(.text+0x84): undefined reference to `glfwPollEvents'
D:\Users\Jorge\AppData\Local\Temp\ccA4Wc7r.o:animation.cpp:(.text+0x90): undefined reference to `glfwWindowShouldClose'
D:\Users\Jorge\AppData\Local\Temp\ccA4Wc7r.o:animation.cpp:(.text+0x9e): undefined reference to `glfwTerminate'
C:\Programming\MinGW32\bin/ld.exe: D:\Users\Jorge\AppData\Local\Temp\ccA4Wc7r.o: bad reloc address 0x20 in section `.eh_frame'
C:\Programming\MinGW32\bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
I can see that the linker is someway unable to link with glfw, but why ? 我可以看到链接器有时无法与glfw链接,但是为什么呢? and what am I doing worng ? 我在做什么? Thanks 谢谢
The command you used to compile is the problem. 您用来编译的命令就是问题所在。 It should be: 它应该是:
g++ main.cpp -lglfw3dll -lopengl32 -lgdi32 -Wall -o main.exe
This is because you first compile main.cpp and then link the libraries to it. 这是因为您首先编译main.cpp,然后将库链接到它。 The gdi32
library is also needed when creating OpenGL context. 创建OpenGL上下文时,还需要gdi32
库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.