如何将 GLEW 与 MinGW 结合使用
我试图使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
恐怕您不能将 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.
(我知道这有点晚了,但我认为它可能会解决其他人的问题,所以)我在编译动态链接到 GLEW 的程序时遇到了一个非常类似的问题。事实证明,我忽略了
libglew32.dll.a
文件 - 该文件也需要存在(除了libglew32.a
和glew32.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 tolibglew32.a
andglew32.dll
that I had previously copied to my project folder.)你可以尝试 GLee ,它基本上与 GLEW 做同样的事情。
You could try GLee which essentially does the same thing as GLEW.
奇怪的是没有人对此说过任何话。默认情况下,在 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
), defineGLEW_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. sourceYou 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 likegcc -c -O2 -DGLEW_STATIC glew.c
instead.