Compiling a minimal GLEW application under Cygwin

Consider the following program and try to compile it under Cygwin:

#include <GL/glut.h> int main(int argc, char** argv) { glutInit(&argc, argv); glLoadIdentity(); } 

It compiles and works fine. -I/usr/include/opengl seems very important.

 g++ -I/usr/include/opengl -I../include/cygwin -L../lib/cygwin test.cpp -o test.exe -lglut32 -lglu32 -lglew32 -lopengl32 

Now,

 #include <GL/glew.h> // from newest NVIDIA SDK #include <GL/glut.h> int main(int argc, char** argv) { glewInit(); glutInit(&argc, argv); glLoadIdentity(); } 

compiled

 g++ -I/usr/include/opengl -I../include/cygwin -L../lib/cygwin test.cpp -o test.exe -lglut32 -lglu32 -lglew32 -lopengl32 

fails. How to create a second application?

First

There are several ways to create glew from the NVIDIA SDK: VS, by cywin, using cygwin with -D_WIN32. I also tried the cygwin compilation from the original source from source.

VS build gives

 /cygdrive/c/DOCUME~1/kelebron/LOCALS~1/Temp/ccErbecl.o:test.cpp:(.text+0xa8): undefined reference to `_glLoadIdentity' collect2: ld returned 1 exit status 

cygwin build give a lot

 ../lib/cygwin/glew32.lib(glew.o):glew.c:(.text+0x38e): undefined reference to `_glXGetProcAddress' 

and cygwin with -D_WIN32 does not compile at all (I was slightly motivated by this post ).

Second

There seem to be two ways to communicate with OpenGL
with -L / lib / w32api
or with -L / usr / X11R6 / lib -lX11 -lXi -lXmu

But, the -L directives do not change anything. I have / usr / lib / w 32api / libopengl32.a, but the version of X11 may be missing (/ usr / X11R6 / lib / libGL?). Which package should I include in Cygwin? I installed everything starting with libGL (not only ...).

+6
source share
4 answers

I had a similar problem a while ago, and I found that there are two ways to compile opengl code under Cygwin.
First links to win32api glut32 glu32 opengl32 native libraries (also glui). They are somewhat older:
glut v3.7.6
opengl v1.1
glui 2.11

The second method uses the X11 glut glu gl libraries. They have a newer version number in their header files (note that using GL extensions requires> v1.2):
waterlogging v4 (freeglut)
opengl v1.3
glext
...

So, to use the first compilation option with: -I / usr / include / opengl
and link to: -lglut32 -lGLU32 -lOpenGL32

To use the X11 version, compile with: -I / usr / include / (which is enabled by default)
and link: -lglut -lGLU -lGL (note the difference)
you can add headers and X11 libraries, but I assume that they are included in GL files.
-I / USR / X11R6 / enable
-L / usr / X11R6 / lib -lXmu -lXi -lXext -lX11


The following packages are available in the Cygwin installer:
opengl - gives win32 version of opengl, glut, glui
libglut-devel is the X11 version for overflow (freeglut), it will also display all dependent packages. (glproto, libGL libGLU, libX11, ...)
I also recommend enabling the Xorg server , since you will need an X server.

Hope this helps.

+6
source

Just to make sure that we are talking about the same issues, here is the message I used.

$ g ++ -o glew_test.exe glew_test.cpp -lglut32 -lglew32
C: \ Users \ Fredrick \ Users \ Fredrick \ AppAppData \ Local \ Temp / ccgSNdfr.o:
glew_test.cpp :(. text + 0x1c): undefined reference to `__glutInitWithExit '
C: \ Users \ Fredrick \ AppData \ Local \ Temp / ccgSNdfr.o:
glew_test.cpp :(. text + 0x37): undefined reference to `__glutCreateWindowWithExit '
C: \ Users \ Fredrick \ AppData \ Local \ Temp / ccgSNdfr.o:
glew_test.cpp :(. text + 0x53): undefined reference to `__glutCreateMenuWithExit '
C: \ Users \ Fredrick \ AppData \ Local \ Temp / ccgSNdfr.o:
glew_test.cpp :(. text + 0x9e): undefined reference to `glutInitDisplayMode '
C: \ Users \ Fredrick \ AppData \ Local \ Temp / ccgSNdfr.o:
glew_test.cpp :(. text + 0xb2): undefined reference to `glutInitWindowPosition '
C: \ Users \ Fredrick \ AppData \ Local \ Temp / ccgSNdfr.o:
glew_test.cpp :(. text + 0xc6): undefined reference to `glutInitWindowSize '
collect2: ld returned 1 exit status

The following pages have helped me with this problem.

Basically, I had to define _STDCALL_SUPPORTED and _M_IX86 at the beginning of the file and include windows.h before glew.h

Then I used the flags -lglut32 -lglew32

If you want to try, here is the source:

 #define _STDCALL_SUPPORTED #define _M_IX86 #include <windows.h> #include <GL/glew.h> #include <GL/glut.h> #include <cstdio> int main(int argc, char **argv) { glutInit(&argc, argv); glutCreateWindow("MM 2004-05"); glewInit(); if (glewIsSupported("GL_VERSION_2_0")) printf("Ready for OpenGL 2.0\n"); else { printf("OpenGL 2.0 not supported\n"); } return 0; } 

Please note that for some reason a window is required for the OpenGL2.0 test.

+3
source

It looks like you want to link yourself to the native Win32 libraries instead of X11. Add -L / lib / w32api. Otherwise, you need to link to the X11 libraries (-L / usr / X11R6 / lib -lX11 -lXi -lXmu) to get rid of glX * linker errors.

+1
source

Was any previous suggestion work for you?

I donโ€™t understand if you are having problems linking or compiling GLEW. I use GLEW through the source and use the link linked in the past.

If you want to compile GLEW, make sure you select the correct zip, because when using scripts based on nix-based scripts, it may not work correctly under windows (not sure about Cygwin).

GLEW should be the first in the header and binding order.

0
source

All Articles