如何将 GLEW 与 MinGW 结合使用

发布于 2024-12-27 06:13:18 字数 1711 浏览 1 评论 0原文

我试图使用glew32.lib文件链接到我的项目中,而不是我自己编译Glew源代码以获得glew.a文件。现在,我的项目中出现了这些链接错误:

g++ -o Chapter10(OpenCLTest).exe src\Chapter10(OpenCLTest).o -lopengl32 -lglew -lglut32 -lglu32 -lopencl
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x167): undefined reference to `_imp____glewBindBuffer'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x39a): undefined reference to `_imp__glewInit'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x3a7): undefined reference to `_imp__glewIsSupported'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x48a): undefined reference to `_imp____glewGenBuffers'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x495): undefined reference to `_imp____glewBindBuffer'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x4dd): undefined reference to `_imp____glewBufferData'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x50b): undefined reference to `_imp____glewGetBufferParameteriv'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x1d67): undefined reference to `_imp____glewBindBuffer'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x1d7f): undefined reference to `_imp____glewDeleteBuffers'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x1d95): undefined reference to `_imp____glewBindBuffer'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x1dad): undefined reference to `_imp____glewDeleteBuffers'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x2078): undefined reference to `_imp____glewBindBuffer'
collect2: ld returned 1 exit status

解决这个问题很好,但是顺便问一下,还有其他的 gl 扩展的 opengl 实现吗?

I was trying to use glew32.lib file to link in my project, than I compile Glew source by myself to get glew.a file. Now, I have these link errors in my project:

g++ -o Chapter10(OpenCLTest).exe src\Chapter10(OpenCLTest).o -lopengl32 -lglew -lglut32 -lglu32 -lopencl
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x167): undefined reference to `_imp____glewBindBuffer'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x39a): undefined reference to `_imp__glewInit'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x3a7): undefined reference to `_imp__glewIsSupported'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x48a): undefined reference to `_imp____glewGenBuffers'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x495): undefined reference to `_imp____glewBindBuffer'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x4dd): undefined reference to `_imp____glewBufferData'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x50b): undefined reference to `_imp____glewGetBufferParameteriv'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x1d67): undefined reference to `_imp____glewBindBuffer'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x1d7f): undefined reference to `_imp____glewDeleteBuffers'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x1d95): undefined reference to `_imp____glewBindBuffer'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x1dad): undefined reference to `_imp____glewDeleteBuffers'
src\Chapter10(OpenCLTest).o:Chapter10(OpenCLTest).cpp:(.text+0x2078): undefined reference to `_imp____glewBindBuffer'
collect2: ld returned 1 exit status

It is good to solve this problem but by the way I want to ask are there any other opengl implementaions of gl extentions?

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

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

发布评论

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

评论(4

饮惑 2025-01-03 06:13:18

恐怕您不能将 glew.lib 与 g++ 一起使用(因为 .lib 是 Microsoft 专有格式)。您收到的这些错误缺少函数入口点,这意味着您没有正确编译 GLEW(所需的函数未在 .so 中导出 - 需要了解更多详细信息才能解决此问题)。

至于问题的其他部分,您可以尝试GLEH。它仍处于开发阶段,可能需要一些调整才能为您工作,但我们已经在 Linux 中非常成功地使用它,所以它应该不会太糟糕。

I'm afraid you can't use glew.lib with g++ (because .lib is a proprietary Microsoft format). These errors you get are missing function entry points, meaning that you didn't compile GLEW correctly (the required functions are not exported in your .so - need to know more details in order to be able to solve this issue).

As for the other part of the question, you can try GLEH. It is still in the development phase and may need some tweaking to work for you, but we've been using it quite successfuly in linux so it shouldn't be too bad.

や莫失莫忘 2025-01-03 06:13:18

(我知道这有点晚了,但我认为它可能会解决其他人的问题,所以)我在编译动态链接到 GLEW 的程序时遇到了一个非常类似的问题。事实证明,我忽略了 libglew32.dll.a 文件 - 该文件也需要存在(除了 libglew32.aglew32.dll< /code> 我之前已将其复制到我的项目文件夹中。)

(I know this is a bit late, but I figured it might solve someone else's problem, so) I had a very similar problem compiling a program that linked to GLEW dynamically. It turns out that I had overlooked the libglew32.dll.a file - that also needed to be present (in addition to libglew32.a and glew32.dll that I had previously copied to my project folder.)

朦胧时间 2025-01-03 06:13:18

你可以尝试 GLee ,它基本上与 GLEW 做同样的事情。

You could try GLee which essentially does the same thing as GLEW.

月依秋水 2025-01-03 06:13:18

奇怪的是没有人对此说过任何话。默认情况下,在 Windows 上,GLEW 标头对所有外部函数使用 declspec(dllimport),这会破坏其所有名称。这就是为什么所有缺失的外部符号名称的前面都有 _imp____

如果您不想使用 GLEW 的静态构建(您提到了有关 libglew.a 的内容),请在构建 GLEW 和构建应用程序期间定义 GLEW_STATIC 。这将取消静态链接的名称。

如果您想链接到 GLEW 的共享库版本,请确保使用 GLEW_BUILD 构建 GLEW。我不确定 gcc 是否有必要这样做,但如果库是用 MSVC 构建的,则需要这样做。

此外,GNU 工具链实际上支持 Microsoft 的 .lib 格式进行链接。

您可能会发现最简单的方法是自己编译 GLEW,甚至将其包含在您的项目中。它只有一个源文件和几个头文件。要手动编译该库,请使用类似于 gcc -shared -o libGLEW.dll -Wl,--out-implib=libGLEW.dll.a -O2 -DGLEW_BUILD glew.c 的内容。要获取静态版本,请使用类似 gcc -c -O2 -DGLEW_STATIC glew.c 的内容。

Strange nobody has said anything about this. By default on Windows, the GLEW headers use declspec(dllimport) for all of the external functions, which mangles all of their names. This is why all of the missing external symbol names all have _imp____ at the front.

If you wan't to use a static build of GLEW (you mentioned something about libglew.a), define GLEW_STATIC during the build of GLEW and during the build of your application. This will unmangle the names for static linking.

If you want to link to a shared library version of GLEW, make sure to build GLEW with GLEW_BUILD. I'm not sure if this is necessary with gcc but it is if the library is built with MSVC.

Furthermore, the GNU toolchain actually supports Microsoft's .lib format for linking. source

You may find it easiest to just compile GLEW yourself or even include it in your project. It is only one source file and a few headers. To compile the library manually, use something along the lines of gcc -shared -o libGLEW.dll -Wl,--out-implib=libGLEW.dll.a -O2 -DGLEW_BUILD glew.c. To get the static version use something like gcc -c -O2 -DGLEW_STATIC glew.c instead.

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