我一直在使用SDL学习OpenGL,但是我正在学习使用GLUT的教程,我试图切换到GLUT,因为它看起来更容易用于新手,我觉得我会更快地选择内容。我认为这将是一个简单快速,无痛的过程,但是在尝试编译GLUT内容时遇到以下问题(使用MinGW) (我已经下载了GLUT并将头文件解压缩到我的包含,因此它被正确包含在内,我还将lib文件解压缩到lib文件夹中,并且我正在链接它,我的DLL中存在.DLL for glut system32所以它被成功调用。
我对自己做错了什么一无所知,不胜感激任何帮助和建议
在编译以下小内容时构建消息(目前不会执行任何操作但应编译):
#include <stdlib.h>
#include <GL/glut.h>
static int day = 0, year = 0;
void init()
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glPushMatrix();
glutWireSphere(1.0,20,16);
glRotatef((GLfloat) year, 0.0,1.0,0.0);
glTranslatef(2.0,0.0,0.0);
glRotatef((GLfloat) day, 0.0, 1.0, 0.0);
glutWireSphere(0.2,10,8);
glPopMatrix();
glutSwapBuffers();
}
//void reshape(int w, int h)
int main(int argc, char **argv)
{
}
构建器错误:
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `__glutInitWithExit'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `__glutCreateWindowWithExit'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `__glutCreateMenuWithExit'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glClearColor'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glShadeModel'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glClear'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glColor3f'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glPushMatrix'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `glutWireSphere'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glRotatef'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glTranslatef'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glRotatef'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `glutWireSphere'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glPopMatrix'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `glutSwapBuffers'|
||=== Build finished: 15 errors, 0 warnings ===|
答案 0 :(得分:2)
是的,我必须包含这段代码才能让它在Windows上运行。
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#endif
似乎windows上的链接器通过windows.h链接来访问System32中的.dll文件
答案 1 :(得分:0)
不,你没有反对过剩(也不是gl)。或者它是一个糟糕的版本,但我怀疑。您可以尝试发布项目配置或Makefile。 _imp__gl*
事物是libGL,显然glut*
事情是过剩的。此外,请确保链接到链接器可识别的库格式。 * .lib文件通常是MS-COFF格式,这是微软自己的COFF标准。 mingw(ld)中的链接器将无法链接此文件。您需要一个扩展名为.a
的静态库(通常)。