Compiling minimal GLEW application under Cygwin

后端 未结 4 460
别那么骄傲
别那么骄傲 2020-12-17 00:52

Let\'s consider the following program and try to compile it under Cygwin:

#include 
int main(int argc, char** argv)
{
    glutInit(&argc,         


        
相关标签:
4条回答
  • 2020-12-17 01:29

    Just to make sure we're talking about the same issues, here's the message I used to get.

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

    The following pages helped me with this issue.

    • www.mingw.org/node/28
    • glew.sourceforge.net/install.html

    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 it out, here's the source as well:

    #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;
    }
    

    Note that the window, for some reason, is needed for the OpenGL2.0 test.

    0 讨论(0)
  • 2020-12-17 01:37

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

    0 讨论(0)
  • 2020-12-17 01:51

    Did any previous suggestion work for you?

    I am not clear whether you are facing issues in linking or compiling GLEW. I use GLEW via including source and have used by linking in past.

    If you want to compile GLEW then make sure you pick right zip, as using *nix based code's scripts may not run correctly under windows (not sure of Cygwin).

    GLEW should be first in header and linking order.

    0 讨论(0)
  • 2020-12-17 01:52

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

    The second way uses the X11 libraries glut glu gl. They have newer version number in their header files (Note that to use GL extensions requires >v1.2):
    glut v4 (freeglut)
    opengl v1.3
    glext
    ...

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

    To use the X11 version, compile with: -I/usr/include/ (which is included by default)
    and link with: -lglut -lGLU -lGL (note the difference)
    you could add the X11 headers and libraries but I guess their included by the GL ones.
    -I/usr/X11R6/include
    -L/usr/X11R6/lib -lXmu -lXi -lXext -lX11


    In the Cygwin installer, the following packages are your choices:
    opengl -- gives the win32 version of opengl, glut, glui
    libglut-devel -- X11 version of glut (freeglut), this will also pick all dependent packages. (glproto, libGL libGLU, libX11, ...)
    I also recommend including the Xorg-server since you will need an X server.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题