在MinGW上链接GLFW时出现未定义的参考错误

编程入门 行业动态 更新时间:2024-10-24 07:34:19
本文介绍了在MinGW上链接GLFW时出现未定义的参考错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用minGW在Windows上使用GLEW和GLFW开发一个openGL应用程序.在当前目录project/中,我具有目录src/,bin/和glfw-3.0.4.bin.WIN64/.我在src/目录中有文件test.cpp,glew.h,glew.c和wglew.h.

I am trying to develop an openGL application with GLEW and GLFW on Windows using minGW. In the current directory, project/, I have the directories src/, bin/, and glfw-3.0.4.bin.WIN64/. I have the files test.cpp, glew.h, glew.c, and wglew.h in the src/ directory.

目录./glfw-3.0.4.bin.WIN64/include/包含GLFW/glfw3.h头文件.

目录./glfw-3.0.4.bin.WIN64/lib-mingw/包含glfw3.dll,glfw3dll.a和libglfw3.a.

我的主文件test.cpp包含

#include "glew.h" #include "GLFW/glfw3.h" #include <stdio.h> int main(int argc, char** argv) { printf("Hello, World!\n"); glewInit(); glfwInit(); }

我正在通过运行从project/目录编译程序(为了便于阅读,分为两行)

I am compiling the program from the project/ directory by running (split into two lines for readability)

gcc -DGLEW_STATIC -DGLFW_DLL -o ./bin/test ./src/*.cpp ./src/glew.c -I ./glfw-3.0.4.bin.WIN64/include/ -L ./glfw-3.0.4.bin.WIN64/lib-mingw/ -lglfw3 -lopengl32

并且出现以下错误:

undefined reference to `_imp_glfwInit'

我认为问题与我错误地链接GLFW库有关.据我了解,包括编译器选项-lglfw3将告诉gcc链接./glfw-3.0.4.bin.WIN64/lib-mingw/glfw3.dll,其中包含glfwInit()的定义.

I think the problem has to do with me linking the GLFW library incorrectly. From what I understand, including the compiler option -lglfw3 will tell gcc to link ./glfw-3.0.4.bin.WIN64/lib-mingw/glfw3.dll, which contains the definition for glfwInit().

我已经研究了类似于我的其他问题的解决方案,并且他们提出了一些建议,例如将dll文件复制到源/二进制目录以及更改-l选项的顺序,但是似乎都没有解决该问题的方法.我.

I've looked at solutions to other problems similar to mine and they suggest things such as copying the dll file to the source/binary directories and changing the order of the -l options, but none have seemed to solve the problem for me.

推荐答案

您的问题是gcc遵循严格的库命名约定.它会尝试找到glfw3.dll.a,但找不到任何内容(因为它名为glfw3dll.a-简单的重命名即可解决您的问题).

Your problem is that gcc follows strict library naming conventions. It attempts to find glfw3.dll.a, but finds none (because it is named glfw3dll.a - simple rename will fix your problem).

下一步,它查找libglfw3.a,并成功-但它是一个静态库,而引用在头文件中声明为动态(棘手的Windows DECLSPECs ...例如在Linux上不存在此问题).因此,它找不到_imp__glfwInit,因为在静态库中它仅称为glfwInit,因此会出现错误.

Next step it looks for libglfw3.a, and succeeds - but it is a static library, while reference declared as dynamic in header files (tricky windows DECLSPECs... this problem don't exist on e.g. linux). So, it cannot find _imp__glfwInit, because in static library it is called just glfwInit, so you getting an error.

删除libglfw3.a也是一种选择-在这种情况下,gcc会进一步查找并最终找到glfw3.dll并使用它.

Removing libglfw3.a is also one of options - in that case gcc will look further and eventually find glfw3.dll and use it.

更多推荐

在MinGW上链接GLFW时出现未定义的参考错误

本文发布于:2023-11-16 18:43:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606846.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   未定义   链接   MinGW   GLFW

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!