簡體   English   中英

GLFW鏈接無法在C ++中與mingw32正常使用(?)

[英]GLFW link not working correctly with mingw32 in C++ (?)

我正在嘗試從GLFW網頁編譯此示例:

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;
}

我使用的是mingw32,我從此處http://www.glfw.org/download.html下載了32位Windows二進制文件。

我把它們放在各自的文件夾中:

C:\\Programming\\MinGW32\\bin glfw3.dll ,我的main.cpp文件夾中的副本。

C:\\Programming\\MinGW32\\lib glfw3dll.alibglfw3.a

GLFW folder及其.h文件位於C:\\Programming\\MinGW32\\include

要編譯所有文件,請使用以下代碼: g++ -lglfw3dll -lopengl32 main.cpp -Wall -o main.exe

這是我得到的錯誤:

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

我可以看到鏈接器有時無法與glfw鏈接,但是為什么呢? 我在做什么? 謝謝

您用來編譯的命令就是問題所在。 它應該是:

g++ main.cpp -lglfw3dll -lopengl32 -lgdi32 -Wall -o main.exe

這是因為您首先編譯main.cpp,然后將庫鏈接到它。 創建OpenGL上下文時,還需要gdi32庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM