Windows C++如何安装GLFW库?

3

我正在编写游戏窗口部分的代码。代码出现了错误,我认为错误的原因是缺少 GLFW 库。我使用 Notepad++ 进行编辑,MinGW 进行编译。我该如何将库安装到我的文件夹中?

错误信息:

NPP_SAVE: C:\Users\User\Desktop\game\src\main.cpp
CD: C:\Users\User\Desktop\game\src
Current directory: C:\Users\User\Desktop\game\src
g++ "main.cpp" -o main -march=native -O3
Process started (PID=1568) >>>
In file included from main.cpp:4:
Display.h:7:10: fatal error: GLFW/glfw3.h: No such file or directory
 #include <GLFW/glfw3.h>
          ^~~~~~~~~~~~~~
compilation terminated.
<<< Process finished (PID=1568). (Exit code 1)
NPP_RUN: main
; executing: NPP_RUN main
- the specified file was not found
================ READY ================
1个回答

5
您不需要安装库,只需告诉编译器您需要的头文件和库在哪里即可。如何执行此操作取决于您的构建环境。 如果您仅使用mingw g ++,则需要以下选项:
  • -I(大写I!)(指定包含文件的路径,在您的情况下是glfw / include目录的路径)
  • -L(库的路径,在您的情况下为包含glfw3.lib的文件夹的路径)
  • -l(小写L!)(要使用的库列表,在您的情况下为glfw3,不带扩展名)

我需要将GLFW库的压缩文件添加到C:\MinGW\include吗? - bapap
不,你为什么要这样做呢?你需要先提取它。无论你喜欢放在哪里,然后告诉编译器在哪里找到这些文件即可。 - Lukas-T
我将文件提取到了我的程序的“Dependencies”文件夹中。 我键入了 g++ -l C:\Users\User\Desktop\game\Dependencies,但出现了错误。 错误:c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lC:\Users\User\Desktop\game\Dependencies - bapap
-l adds a libary by name, as I said. It should be -lglfw3 - Lukas-T
谢谢!它有效了。但我的程序的exe文件出现了这个错误:程序太大,无法放入内存。我该如何解决这个问题?我是C++新手。 - bapap
1
最好为此提出一个新问题 ;) - Lukas-T

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接