简体   繁体   English

GLFW链接无法在C ++中与mingw32正常使用(?)

[英]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.alibglfw3.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.

相关问题 使用MINGW32在Debian上使用C ++和MySQL进行编译 - Compile with C++ & MySQL on Debian using MINGW32 错误(mingw32/bin/ld.exe 最终链接失败:设备上没有剩余空间)构建 C++ 项目 - Error (mingw32/bin/ld.exe final link failed: No space left on device) building C++ project mingw32无法链接到库 - mingw32 can't link to library c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe:最终链接失败:设备上没有剩余空间 - c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: final link failed: No space left on device 有关来自MinGW32的复制构造函数的疯狂C ++编译器错误消息 - crazy C++ compiler error messages about a copy constructor from MinGW32 Armadillo C ++和BLAS和ATLAS在mingw32下找不到lapack blas - Armadillo C++ and BLAS and ATLAS cannot find lapack blas under mingw32 如何减少pthread_join的影响。 Mingw32,C ++ - How can I reduce the effect of pthread_join. Mingw32, c++ C ++ Mingw32 CreateProcess()失败,错误代码为2:系统找不到指定的文件 - C++ Mingw32 CreateProcess() failed with error code 2: The system cannot find the file specified 如何在 QtCreator 中使用 qmake 和 MinGW32 链接动态库? - How to link a dynamic library in QtCreator use qmake and MinGW32? Qt / mingw32未定义的引用错误...无法链接.lib - Qt/mingw32 undefined reference errors… unable to link a .lib
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM