Compiling minimal GLEW application under Cygwin

后端 未结 4 462
别那么骄傲
别那么骄傲 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 
    #include 
    #include 
    #include 
    
    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.

提交回复
热议问题