简体   繁体   English

链接 GLFW 时“未定义对 __mingw_free 的引用”

[英]"undefined reference to __mingw_free" when linking GLFW

This is my first question on this site.这是我在这个网站上的第一个问题。 I am also very new to c++ and am not that great in english, so sorry for that.我对 c++ 也很陌生,英语也不是很好,很抱歉。 I know that there are a lot of questions on stackoverflow that sound like mine, but the answers don't seem to work.我知道 stackoverflow 上有很多听起来像我的问题,但答案似乎不起作用。 example: MinGW Linking GLFW gets errors示例: MinGW Linking GLFW 出错

the link shows one of the many questions i've found.该链接显示了我发现的众多问题之一。 I've been searching for an answer for a couple of days now, so i decided to make an account.这几天我一直在寻找答案,所以我决定注册一个帐户。

I use windows 10 and have installed mingw correctly(i think).我使用 windows 10 并正确安装了 mingw(我认为)。 And for GLFW I used the 32-bit binaries from here: https://www.glfw.org/download.html对于 GLFW,我使用了这里的 32 位二进制文件: https://www.glfw.org/download.html

The code i used is the official example on the glfw page.我使用的代码是 glfw 页面上的官方示例。 It is as follows:如下:

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

my mingw version(g++ --version):我的 mingw 版本(g++ --version):

g++ (MinGW.org GCC-6.3.0-1) 6.3.0

I've put the "GLFW" folder from the GLFW binaries into "C:\MinGW\include", which works perfectly.我已将 GLFW 二进制文件中的“GLFW”文件夹放入“C:\MinGW\include”,效果很好。

And I've put the file "libglfw3.a" into "C:\MinGW\lib".我已将文件“libglfw3.a”放入“C:\MinGW\lib”。 I've also put the file "libglfw3dll.a" into "C:\MinGW\lib".我还将文件“libglfw3dll.a”放入“C:\MinGW\lib”。

my cmd command:我的 cmd 命令:

g++ main.cpp -lglfw3 -lopengl32 -lgdi32

I also tried it with -luser32 -lkernel32 and -lmingw32, but all of them do nothing我也用 -luser32 -lkernel32 和 -lmingw32 试过了,但它们都什么都不做

I tried linking with the dll, by using "g++ main.cpp -lglfw3dll -lopengl32 -lgdi32" and moving the "glfw3.dll" into the project folder... and it worked, but i want to link it statically without the dll(if that is dumb or dosn't work please tell me).我尝试通过使用“g++ main.cpp -lglfw3dll -lopengl32 -lgdi32”并将“glfw3.dll”移动到项目文件夹中来与 dll 链接......它有效,但我想在没有 dll 的情况下静态链接它(如果这很愚蠢或不起作用,请告诉我)。

The erorr i'm getting is this:我得到的错误是:

c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(init.c.obj):init.c:(.text+0xb9): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(init.c.obj):init.c:(.text+0xda): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(init.c.obj):init.c:(.text+0x11c): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(init.c.obj):init.c:(.text+0x2bf): undefined reference to `__mingw_realloc'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(input.c.obj):input.c:(.text+0x1016): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(input.c.obj):input.c:(.text+0x1021): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(input.c.obj):input.c:(.text+0x102c): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(input.c.obj):input.c:(.text+0x240c): undefined reference to `__mingw_realloc'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(input.c.obj):input.c:(.text+0x17d6): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(monitor.c.obj):monitor.c:(.text+0xc2): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(monitor.c.obj):monitor.c:(.text+0xd0): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(monitor.c.obj):monitor.c:(.text+0xde): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(monitor.c.obj):monitor.c:(.text+0x114): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(monitor.c.obj):monitor.c:(.text+0x122): more undefined references to `__mingw_free' follow
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(monitor.c.obj):monitor.c:(.text+0x2bd): undefined reference to `__mingw_realloc'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(monitor.c.obj):monitor.c:(.text+0x392): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(monitor.c.obj):monitor.c:(.text+0x3a0): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(monitor.c.obj):monitor.c:(.text+0x3ae): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(monitor.c.obj):monitor.c:(.text+0x3e4): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(monitor.c.obj):monitor.c:(.text+0x3f2): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(monitor.c.obj):monitor.c:(.text+0x400): more undefined references to `__mingw_free' follow
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xe46): undefined reference to `__mingw_realloc'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xf31): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xf69): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xf7b): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x1fbc): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x23c9): undefined reference to `__mingw_free'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x505c): more undefined references to `__mingw_free' follow
collect2.exe: error: ld returned 1 exit status

As you can see the error has something to do with "__mingw_free", but i don't know what that is.如您所见,该错误与“__mingw_free”有关,但我不知道那是什么。

Again, this is my first post and I started learning c++ two weeks ago, so sorry if this is a dumb question... I hope you can help me, Thanks.同样,这是我的第一篇文章,两周前我开始学习 c++,如果这是一个愚蠢的问题,很抱歉......我希望你能帮助我,谢谢。

As the comments pointed out, i updated my g++ version.正如评论所指出的,我更新了我的 g++ 版本。 I uninstalled MinGW and installed it again with msys2.我卸载了 MinGW 并用 msys2 重新安装了它。 And it worked!它奏效了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM