OpenGL C++g++编译器,无法在Windows 10(没有Visual Studio)上找到GLFW
OpenGL C++ with g++ compiler, not able to find GLFW on Windows 10 (no Visual Studio)
我正在尝试使用带有g++编译器的C++从头开始设置OpenGL API。目前,我正在尝试使用 GLFW 获取一个简单的窗口系统,但是当我编译程序时,它似乎找不到 GFLW 目录。
我正在尝试从头开始执行此操作,所以我不会使用任何像Visual Studio这样的IDE,我所做的一切都是用记事本++编写的,并使用git bash的命令编写。我想这样做,我知道这是很多额外的工作,但这就是我想要实现的目标。
我的项目文件夹如下所示:
-TestProject
-main.cpp
-GFLW
-gflw3.h
在我的主文件中.cpp我已经复制粘贴了 GFLW 文档中的代码:
#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;
}
为了编译程序,我将 git bash 与以下命令一起使用:
g++ main.cpp -o WindowApp.exe
现在应该创建一个 exe,使我能够打开一个窗口,仅此而已。显然我做错了什么,首先我收到错误消息,找不到目录 GFLW。所以这是一个问题。
基本上,我想在这里遵循本教程ChernoProject,但不必使用Visual Studio或任何其他IDE。我知道他使用的文件与我不同,并且他做了一些叫做Linking
的东西,但我不明白这如何适应我在这里的极简主义设置。
您包含相对于编译器搜索路径GLFW/glfw3.h
(带尖括号),但标头位于项目的目录树中。编译器不会在项目树中搜索系统标头(包含在尖括号中),除非您通过传递参数明确告诉它这样做-Iinclude_directory
。因此,在您的情况下,您需要包含如下标头:#include "GLFW/glfw3.h"
(推荐),或者添加-I.
参数以告诉编译器在当前目录中搜索系统标头。
同样关于链接 - 这将是您解决标题问题后的下一个问题。您的编译命令如下所示:g++ main.cpp -o WindowApp.exe
并且不包含任何要链接到的库。如果您使用的是 MinGW,它必须包含以下用于静态链接到 OpenGL 和 GLFW3 的参数:-lmingw32 -lglfw3 -lopengl32 -lgdi32 -luser32
。
例如,我对这个项目的首选设置是:
-ProjectDirectory
-bin
-glfw3.dll (if you want to use dll)
-include
-GLFW
-glfw3.h
-glfw3native.h
-lib
-libglfw3.a
-libglfw3dll.a (if you want to use dll)
-src
-main.cpp
-build.bat
使用下面的构建内容.bat(将"Your actual path to g++"
更改为系统上 g++ 的路径,或者如果它在 path 变量中,则将其设置为"g++"
):
@ECHO OFF
REM Path to g++
SET G="Your actual path to g++"
SET OBJECTS=
REM Recursive every .cpp file in ./src
FOR /R "./src" %%a IN (*.cpp) DO (
CALL SET OBJECTS=%%OBJECTS%% "%%a"
)
@ECHO ON
%G% %OBJECTS% -obin/a.exe -Iinclude -Llib -lmingw32 -lglfw3 -lopengl32 -lgdi32 -luser32
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 试图在visual studio上用C++创建一个桌面应用程序
- 如何在MS Visual Studio 2019中运行QT UI
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- Visual Studio Code - C++ Debugger 無法啟動
- Visual Studio 2019:插入多个C++风格的单行注释
- Visual Studio Code "undefined reference to `WinMain@16'"
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- Visual Studio中的函数声明和函数定义问题
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- Visual Studio mkl_link_tool.exe链接错误
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 不同的Visual Studio版本中缺少.dll
- 用Visual Studio在C++中嵌入Julia
- Visual Studio 2017循环自动向量化问题
- 有没有办法在远程设备上打开和编辑visual Studio 2017解决方案
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- Visual Studio在尝试读取resource.txt文件时崩溃
- Visual Studio 2017 不允许我创建 C++ 专用模板