开发者

Problems linking GLEW into SFML project using CodeBlocks

So I'm trying to learn to write shaders and incorporate them into my OpenGL program (I use SFML 1.6 to create a valid OpenGL environment rather than mucking around with GLUT; my IDE is Codeblocks; my card supports OpenGL 3.1 and GLSL 1.3). I've hit a snag, however; it looks like I need GLEW to help incorporate GLSL shaders into my program. So I went and found the source code to GLEW and compiled it as static libraries using CodeBlocks, as per instructions of the final comment here (I added #define GLEW_STATIC to the c. file, since it wasn't clear to me where I was supposed to add it), so that I now have four .a files:

libglew32.a, libglew32d.a, libglew32mx.a, libglew32mxd.a

I've told my compiler where to find the header files (glew.h, glxew.h, wglew.h), and I've told the linker where to find the libraries (above), by adding the relevant directories to Settings->Compiler & Debugger...->Search Directories. In my project, under Build Options->Linker Settings->Link Libraries, I've also linked the four above.

Doing all of the above, I got the following error when trying to call glewInit():

undefined reference to '_imp__glewInit'

Some reading told me that I needed to add #define GLEW_STATIC before #include <glew.h>, so I did that, and now I get a whole slew of undefined reference to "wglGetProcAddress@4" errors (the only line of GLEW code in my program is glewInit();):

 Design\Learning C++\OPEN-GL\OpenGL Experiment 6 - 27-block Terrain Test\main.cpp||In function 'int main()':|
 Design\Learning C++\OPEN-GL\OpenGL Experiment 6 - 27-block Terrain Test\main.cpp|43|warning: unused variable 'LightOn'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `glGetString@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| more undefined references to `wglGetProcAddress@4' follow|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetCurrentDC@0'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\开发者_JS百科MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| more undefined references to `wglGetProcAddress@4' follow|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `glGetString@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `glGetString@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetProcAddress@4'|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| more undefined references to `wglGetProcAddress@4' follow|
C:\Program Files (x86)\CodeBlocks\MinGW\downloaded\glew-1.7.0\afiles\libglew32.a(glew.o):glew.c|| undefined reference to `wglGetCurrentDC@0'|
||=== Build finished: 23 errors, 1 warnings ===|

I'm at a loss; the technical aspects of all this (linking/compiling/etc.) are still new and confusing to me.

What do I need to do in order to get GLEW to work, so that I can incorporate GLSL shaders into my SFML OpenGL project? (Or can I somehow do so more easily without GLEW or any other external libraries? Which would be awesome!)


You also need to link opengl32.lib. Those functions missing the linker complains about are part of opengl32.dll and to access it you need to link against it. Not in the static library, but in your final program. Technically static libraries are nothing else like archives of object files, i.e. the result of the compilation stage. Linking to DLLs requires to happen in the context of an executable binary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜