2
votes

I want to use the cygwin32 compiler instead of mingw32. According to http://web.eecs.umich.edu/~sugih/courses/eecs487/glut-howto/glfw/ , the GLX programs of gl on cygwin don't work with glfw. So I tried to use mingw32 binaries of glfw3 in cygwin32, which gave errors like 'GL_ARRAY_BUFFER' was not declared in this scope. I solved that by linking with mingw32 binaries of glew32, which gave

/usr/include/w32api/GL/glu.h:68:79: error: expected ')' before '*' token

which I solved two different ways, by instead using the glew installed by cygwin or by linking to glew32s and pasting

#ifndef CALLBACK
#if defined(_ARM_)
#define CALLBACK
#else
#define CALLBACK __stdcall
#endif
#endif

#define GLEW_STATIC

If I used glew32 instead of glew32s, it would say undefined reference to 'glewInit', which I need to stop the segfault right before the glCreateShader and after glfwMakeContextCurrent. But this method gave Warning: resolving _glewInit by linking to _glewInit@0.

After all that, I got a lot of errors like undefined reference to 'glGenTextures' or 'glDrawElements', which I could only solve by linking to cygwin's gl, which I think is mixing GLX with WGL. According to glewInit() fails with "Missing GL version", SDL2 OpenGL context, cygwin compiler , I should just switch to mingw32 compiler, which I already have working, but I really want to use cygwin.

If I use cygwin's gl (-lGL) with glew32s, it compiles, runs, and segfaults with a stackdump at my glGenBuffers(1, &ibo); in my model class without glewinit() giving any errors.

model(vectx* vecticesd, unsigned int* indicesd,int vectsized,int indsized,GLuint texidd) :
vecticesarr(vecticesd), indicesarr(indicesd),texid(texidd),vectsize(vectsized),indsize(indsized){
    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, vectsized, vecticesarr, GL_STATIC_DRAW);
    glGenBuffers(1, &ibo);                      //here it crashes
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, indsized, indicesd, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

If I use cygwin's glew instead, the glewinit() returns the error "Missing GL version". glfwMakeContextCurrent(window); is called BEFORE glewinit();. Here is my linkers and doubling them, so the orders don't matter, didn't change anything.

 -lglfw3 -lglew32s -lopengl32 -lgdi32 -lGL

I tried mingw64 binaries with cygwin64 and it gave "___vsnprintf not found" and -lntdll didn't fix it.

--added more information--

I'm new to programming, so please forgive me if I say anything really dumb. For a test case, use the code at https://www.glfw.org/docs/3.0/quick.html . I get a black window with my cygwin32 build setup and the rotating triangle with my mingw32 build setup. I'm using sublime text on windows, if that matters. Can I use the pre-compiled binaries for mingw32 download from the glfw website, or do I have to use cmake with cygwin? When I tried cmake with cygwin by adding cygwin/bin to the environment system variable path, it said "Using Win32 for window creation", and both the cygwin/bin/make.exe and gnu windows make said

[ 16%] Linking C executable boing.exe ../src/glfw3.lib(win32_monitor.c.obj):win32_monitor.c:(.text+0x77): undefined reference to `_imp__CreateDCW@16' ... more errors

If I went into the cmakelist.txt in the glfw source and forced it to use X11, it said "Using X11 for window creation" and then make said X11/extensions/xf86vmode.h was missing and there wasn't a package for it in the setup-x86.exe thing for cygwin. I might of did something very wrong with the cmake, but I don't know. I was able to cmake, make, and make install with mingw32 as the native compiler in the environment system variable path.

1
Mixing cygwin and mingw is never a good idea. About the "don't work with glfw" you can check again or make a simple test and ask here or on the cygwin mailing list. For the rest please provide a STC (simple test case) otherwise it is difficult to help you.matzeri
I'm new to programming, so please forgive me if I say anything really dumb. For a test case, use the code at glfw.org/docs/3.0/quick.html . I get a black window with my cygwin32 setup and the rotating triangle with my mingw32 setup. I'm using sublime text on windows, if that matters. Can I use the pre-compiled binaries for mingw32 download from the glfw website, or do I have to use cmake with cygwin? I wrote some more in the question part above.Crayons4Dinner
@matzeri: I forgot to put this notify thing in my reply.Crayons4Dinner
I have a rotating colored triangle on cygwin 64 bit. How you built the glfw library for cygwin ?matzeri
@matzeri I couldn't figure out how to build it. I tried to use cmake with cygwin.Crayons4Dinner

1 Answers

1
votes

I suspect you are using the wrong libraries so here is a step by step on how to do it on Cygwin. You need the to install of course cmake, make, libGL-devel, xinit and xwin-xdg-menu

To run the Xserver and a X terminal

enter image description here

It will shows two icons on the taskbar, go for the green X and run Xterm.

enter image description here

To compile:
Download the source from https://www.glfw.org/download.html

$ unzip glfw-3.2.1.zip
$ cd glfw-3.2.1
$ cmake -DBUILD_SHARED_LIBS=ON .
$ make
$ make install
$ mv /usr/local/lib/cygglfw-3.dll /usr/local/bin/cygglfw-3.dll

the mv is needed as the proper place for shared lib on Cygwin is the bin directory After that the example can be compiled with

$ gcc simple.c -o simple -lglfw -lgl  -L/usr/local/lib

and run in a Xterminal with

$ ./simple.exe

and this is a snapshot

colored triangle

To build all the samples:

$ cd examples
$ cmake .
$ make

and all are built at ones

$ ls *.exe
boing.exe  heightmap.exe  simple.exe     wave.exe
gears.exe  particles.exe  splitview.exe