GLUT program link error

爱⌒轻易说出口 提交于 2019-12-01 10:48:06

Try it with libglut.a and libglut32.a instead of glut32.lib. To compile glut programs with minGW.

Do GLUT for Win32 is a Windows port of the original GLUT library. It’s no longer maintained or supported. The MinGW “w32api” package already comes with two GLUT import libraries, “libglut.a” and “libglut32.a”, but doesn’t come with a glut header file.

If you’ve ever downloaded a GLUT header from the internet, and attempted to link an application against either of these import libraries, you likely would have seen it fail with various undefined references.

Setting Up GLUT for Win32 With MinGW Look for Setting Up GLUT for Win32 With MinGW

If you want to have your own "build" of libglut32.a and glu32.dll.

Add the following lines to include/GL/glut.h starting at line 12:

 #ifdef __MINGW32__
 #define APIENTRY __stdcall
 #define CALLBACK __stdcall
 #endif

Comment out line 21 in lib/glut/win32_winproc.c so that it looks:

//#include <crtdbg.h>

makefile line 5 replace:

-enable-auto-import with --enable-auto-import

run make


Have tried it with the example.c file from the guidance in the link Setting Up GLUT for Win32 With MinGW.

With the prebuild libs and the self compiled libs. Works both.

below is the result.

Example GLUT Application

example.c from the link above Setting Up GLUT for Win32 With MinGW.

#include <stdlib.h>
#include <GL/glut.h>

void keyboard(unsigned char key, int x, int y);
void display(void);


int main(int argc, char** argv)
{
  glutInit(&argc, argv);
  glutCreateWindow("GLUT Test");
  glutKeyboardFunc(&keyboard);
  glutDisplayFunc(&display);
  glutMainLoop();

  return EXIT_SUCCESS;
}


void keyboard(unsigned char key, int x, int y)
{
  switch (key)
  {
    case '\x1B':
      exit(EXIT_SUCCESS);
      break;
  }
}


void display()
{
  glClear(GL_COLOR_BUFFER_BIT);

  glColor3f(1.0f, 0.0f, 0.0f);

  glBegin(GL_POLYGON);
    glVertex2f(-0.5f, -0.5f);
    glVertex2f( 0.5f, -0.5f);
    glVertex2f( 0.5f,  0.5f);
    glVertex2f(-0.5f,  0.5f);
  glEnd();

  glFlush();
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!