为 Windows 编译带有 GLUT 头文件的 C 程序(在 Linux 中)

发布于 2024-12-27 16:52:36 字数 588 浏览 1 评论 0原文

我目前可以使用 stdio.h 编译 C 程序,例如使用命令 i58​​6-mingw32msvc-gcc 在 Windows 上编译 C 程序,但是我无法对 GLUT 程序执行此操作。当为 Linux 编译它时,我使用:(

gcc main.c -lglut -lGLU

我知道,这是不好的做法,因为它是与 a.out 一起出现的)

但是我不确定如何使用 mingw32 在 Windows 上做到这一点。当我运行时

i586-mingw32msvc -lglut -lGLU 

,它返回:

test.c:3:21: error: GL/glut.h: No such file or directory

包含的头文件是:

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

我不确定如何使其能够编译。有什么想法吗?

I can currently compile C programs with stdio.h and such like for Windows with the command i586-mingw32msvc-gcc, however I cannot do this for a GLUT program. When compiling it for Linux I use:

gcc main.c -lglut -lGLU

(I know, bad practice as it comes out with a.out)

Yet I am unsure of how I could do it for Windows using mingw32. When I run

i586-mingw32msvc -lglut -lGLU 

it returns:

test.c:3:21: error: GL/glut.h: No such file or directory

The included header files are:

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

And I am unsure of how to make it able to compile. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞觅青森が 2025-01-03 16:52:36

本质上,该错误告诉您,您的 MinGW GCC 找不到所需的标头。也就是说,因为您正在交叉编译到另一个操作系统,并且头文件可能包含特定于操作系统的内容。不幸的是 OpenGL 就是其中之一。因此,您还必须在 Windows 版本中安装所需的库。

但是,您不应该仅仅从网络上下载一些预编译的二进制文件;还应该下载一些预编译的二进制文件。你需要与 MinGW 匹配的库。您当然可以安装 MinGW 构建的库,这会起作用。不过,我建议采取不同的做法:自己在 MinGW 环境中交叉编译并本地安装所需的所有库。您可以通过将正确的编译器、链接器和前缀传递到每个库的构建配置中来实现此目的。例如,对于基于 autoconf 的 configure (在我的系统上)

CC=i686-mingw32-gcc CXX=i686-mingw32-g++ ./configure --prefix=/usr/i686-mingw

make ;然后 make install 将在 MinGW 环境中构建并安装库及其标头,您可以在其中像任何其他常规安装的库一样使用它们。

Essentially that error tells you, that your MinGW GCC does not find the required headers. That is, because you're cross-compiling to another OS, and header files may contain OS specific things. Unfortunately OpenGL is one of those. So you have to install the required libraries in a Windows version as well.

However you should not just download some precompiled binaries from the web; you need libraries matching MinGW. You can of course install MinGW built libraries, that will work. However I suggest something different: Crosscompile and locally install all the libraries you require in your MinGW environment yourself. You do this, by passing the right compiler, linker and prefixes into the build configuration of each library. For example for autoconf based configure (on my system)

CC=i686-mingw32-gcc CXX=i686-mingw32-g++ ./configure --prefix=/usr/i686-mingw

make ; make install will then build and install the libraries and their headers in the MinGW environment, where you can use them as any other regular installed library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文