Including GLEW in Visual Studio 2008 / C++/CLI

Hi,

I’m trying to plot some scientific data with OpenGL. I want to use windows forms from .net, so I looked for a wrapper for openGL and i found this:
Article 16051/Creating-an-OpenGL-view-on-a-Windows-Form from codeproject.com (sorry, I’m not allowed to include links in this post :frowning: )
I just copypasted the code from the tutorial and it compiles. Now I wanted to add a shader, so I included this line:

GLuint vs = glCreateShader(GL_VERTEX_SHADER);

to the constructor of the example code. (so it looks like this: Paste YtsLK0vM at Pastebin.com).
I now get 5380 warnings which look like this (all warnings and errors are translated by hand from german, so sorry if they don’t sound exactly right):

warning C4394: "__glewCopyTexSubImage3D": An application domain specific symbol should not be marked with __declspec(dllimport) C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\GL\glew.h	15043

And then these errors:

5381	error LNK2020: Unresolved token (0A000016) __imp____glewCreateShader.	GLwindow.obj (thats my file which includes the tutorial code)
5382	error LNK2020: Unresolved token (0A000024) __imp____glewCreateShader.	OpenGL_test.obj (thats the name of the project)
5383	error LNK2001: Unresolved external symbol "__imp___glewCreateShader".	OpenGL_test.obj
5384	error LNK2001: Unresolved external symbol "__imp___glewCreateShader".	GLwindow.obj
5385	fatal error LNK1120: 3 unresolved external links.	C:\Users\ME\Documents\Visual Studio 2008\Projects\OpenGL_test\Debug\OpenGL_test.exe

What I did:
I installed glew as it is advised on the website:
I copied

bin/Release/Win32/glew32.dll	    to     	Windows/system32
lib/Release/Win32/glew32.lib	    to     	Program files (x86)/Microsoft Visual Studio 9.0/VC/Lib
lib/Release/Win32/glew32s.lib	    to     	Program files (x86)/Microsoft Visual Studio 9.0/VC/Lib
include/GL/glew.h	            to     	Program files (x86)/Microsoft Visual Studio 9.0/VC/Include/GL
include/GL/wglew.h	    to     	Program files (x86)/Microsoft Visual Studio 9.0/VC/Include/GL
include/GL/glxew.h	    to     	Program files (x86)/Microsoft Visual Studio 9.0/VC/Include/GL

from the glew-1.10.0-win32-1.zip binary archive.

And I added the following to my project->linker->input->additional dependencies:
glew32.lib
openGL32.lib
glu32.lib
gdi32.lib
User32.lib

Any ideas what is wrong? I hope you can help me :frowning:
Thanks in advance!
Best regards,
Nikolas

Isn’t there anybody out there who can help me?
I mean, it’s basically just including the dll and using a single basic function from it, but I’m unable to :frowning:

No idea about the problem, sorry. Could be that you need to do something extra to make a regular (i.e. non-managed C++ .dll, like the downloaded glew32.dll is) work with the managed C++ when targeting .net.
Is it an option for you to switch fully to C#? Then you could use OpenTK and sidestep the whole thing.

Hi, thanks for the hint.
I don’t think that it’s a problem with the unmanaged dll. I’m using libfftw (which is surely non-managed) in another project in pretty much the same way and it works. Last time I’ve seen this “unresolved external symbol”-error, it was due to a 64-bit dll instead of 32-bit, and after switching to 32 bit, everything worked. So it sounds like the dll doesent get recognized by the glew32.lib somehow. If I remove the glew32.lib from the additional dependencies, several other errors occur, mainly unresolved tokens, so it does find and use the lib.

OpenTK is for .net in general, so it can be used with C++/CLI, too. C# is basically just a simplification of C++/CLI by removing the support for the old C++/C stuff.
The main problem is that I didn’t find any tutorials for using openTK for plotting data. So I wanted to implement the usual OpenGL-approach with glew and follow one of the tutorials on the web. But since I want to stay with my windows::forms that are simple and now well known to me, I had to solve the error here.
If you know a better approach to learn OpenGL and use it with windows::forms and plot my data with it, than I will happily follow your advice.

If you’re using a 32-bit application, then 32-bit DLLs should be placed into Windows/SysWOW64 rather than Windows/System32 (see WoW64 - Wikipedia ).

Hey, thanks for the hint.
I tried that, sadly it didn’t change anything.

Hi,

process of elimination: You must set a current opengl context, then call glewinit() before being able to use any glew. Have you done so? if not, it might help.

let us know.

Get rid of the glew32.lib and use glew32s.lib instead. It’s a bunch of function pointer loading anyway so it doesn’t really matter that it gets statically linked. Compile the library yourself or use the pre-built binaries. If you’re on Visual Studio, in the file which uses glew.h, put this define in front of the include line like this:


// add a define
#define GLEW_STATIC 1

#include <GL/glew.h>
#include <other_headers.h>

// more code goes here
.
.
.

Then put this pragma in your main.cpp file:


#pragma comment(lib, "glew32s.lib")

Make sure to use the x86 version of glew32s.lib if you’re compiling for 32-bit systems. Otherwise use the x64 one which you may need to compile for yourself. I don’t use Glew anymore but I’ve made a bunch of projects in the past that use glew32s.lib because glew32.lib tends to be very finicky.