未定义的引用_imp使用MinGW GCC ____ GLEW *函数 [英] Undefined References to _imp____glew* functions with minGW gcc

查看:1478
本文介绍了未定义的引用_imp使用MinGW GCC ____ GLEW *函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译的Win 7 x64系统上使用MinGW的一个相对简单的OpenGL程序,我不断收到未定义的引用数的GLEW功能。我已经设置链接到项目库中,并已四处找我可以从我的列表中缺少任何库,还从连接器的输出仍然是这样的:

I am trying to compile a relatively simple OpenGL program using MinGW on a Win 7 x64 system, and I keep getting undefined references to several of the GLEW functions. I have set the libraries to link to the programs, and have been looking around for any library I may be missing from my list, yet the output from the linker still looks like this:

16:35:50 **** Incremental Build of configuration Debug for project test ****
Info: Internal Builder is used for build
gcc -LD:/DEV/openGL/lib/x86 -LD:/DEV/x86/lib -o test.exe test.o -lfreeglut -lglaux -lglew32s -lglu32 -lglfw3 -lopengl32 -lgdi32 
test.o: In function `init':
E:\Development\C\test\Debug/../test.c:32: undefined reference to `_imp____glewGenVertexArrays'
E:\Development\C\test\Debug/../test.c:33: undefined reference to `_imp____glewBindVertexArray'
E:\Development\C\test\Debug/../test.c:35: undefined reference to `_imp____glewGenBuffers'
E:\Development\C\test\Debug/../test.c:36: undefined reference to `_imp____glewBindBuffer'
E:\Development\C\test\Debug/../test.c:37: undefined reference to `_imp____glewBufferData'
test.o: In function `display':
E:\Development\C\test\Debug/../test.c:45: undefined reference to  `_imp____glewBindVertexArray'
test.o: In function `main':
E:\Development\C\test\Debug/../test.c:61: undefined reference to `_imp__glewInit@0'
collect2: ld returned 1 exit status

16:35:50 Build Finished (took 675ms)

我试图与这两个-lglew32和-lglew32s在几个不同的配置,以为或许有在都不在glew32 glew32s定义,而这并没有帮助。任何指导,我可能会丢失,或者说我忽略了?

I have tried with both -lglew32 and -lglew32s in several different configurations, thinking that perhaps there were definitions in glew32s that were not in glew32, and this did not help. Any guidance as to what I may be missing, or something I have overlooked?

推荐答案

您需要的#define GLEW_STATIC 的#includeglew.h 如果您使用的是静态链接库。我会继续前进,增加一条规则,你的Makefile定义此pre处理器的道理,而不是的#define ... 在源$ C实际上是把$ C。

You need to #define GLEW_STATIC before #include "glew.h" if you are using the static linking library. I would go ahead and add a rule to your Makefile to define this pre-processor token, rather than actually putting the #define ... in your source code.

这是在GLEW的安装文档提到的,顺便说一句。但是,时代这个问题是问的数量来看,也未必说明不够清楚。

This is mentioned in the installation documentation for GLEW, by the way. But judging by the number of times this question is asked, it may not be stated clearly enough.

原因定义该令牌是微软Windows使用一种特殊的 __ declspec(...)的DLL的进口和出口。通过定义 GLEW_STATIC ,您告诉链接器使用标准的行为来定位符号的的.lib

The reason for defining this token is that Microsoft Windows uses a special __declspec (...) for DLL imports and exports. By defining GLEW_STATIC, you are telling the linker to use standard behavior to locate the symbols in your .lib.

GLEW_STATIC 是不确定的,它通知连接器,该库的符号在运行时解决。但是MSVC需要知道无论是创造出口或寻求进口,所以另一个标记 GLEW_BUILD 定义这种行为。既然你要链接到(进口),而不是建(出口)GLEW,请确保您的确定 GLEW_BUILD

When GLEW_STATIC is undefined, it informs the linker that the library's symbols are resolved at runtime. But MSVC needs to know whether it is creating exports or looking for imports and so there is another token GLEW_BUILD that defines this behavior. Since you want to link to (import), and not build (export) GLEW, make sure you do not define GLEW_BUILD.

/*
 * GLEW_STATIC is defined for static library.
 * GLEW_BUILD  is defined for building the DLL library.
 */

#ifdef GLEW_STATIC
#  define GLEWAPI extern
#else
#  ifdef GLEW_BUILD
#    define GLEWAPI extern __declspec(dllexport)
#  else
#    define GLEWAPI extern __declspec(dllimport)
#  endif
#endif

结果
还值得一提的是,你不能使用pre-内置动态链接的.lib 和DLL文件被官方GLEW网站上提供。他们使用的是MSVC编译;使用与MSVC的MinGW的编译一个DLL看到此链接。更好的解决办法就是避免使用动态链接库,并使用静态库。


It is also worth mentioning that you cannot use the pre-built dynamic linking .lib and DLL files that are supplied on the official GLEW website. They are compiled using MSVC; to use a DLL compiled with MSVC in MinGW see this link. The better solution is just to avoid using the dynamic link library and use the static library.

这篇关于未定义的引用_imp使用MinGW GCC ____ GLEW *函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆