无法在Windows上编译简单的freeglut测试程序

时间:2013-03-10 02:13:36

标签: windows opengl freeglut

我下载了包含freeglut的“非官方OpenGL软件SDK”,但我似乎无法让它工作。我在Windows上。我没有使用Visual Studio 2010或MinGW g ++取得成功。我有一个非常简单的测试程序

#include <GL/glut.h>

int main(int argc, char* argv[])
{ 
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(800, 600);
    glutCreateWindow("GLUT Test");

    glutMainLoop();
    return 0;
}

现在我正在尝试用

编译它
g++ -I/c/Libraries/usr/include -L/c/Libraries/usr/lib -lfreeglut

这是我不断收到的错误消息。

C:\Users\Zachary\AppData\Local\Temp\cckeVUNm.o:gluttest.cpp:(.text+0x1c): undefined reference to `_imp____glutInitWithExit@12'
C:\Users\Zachary\AppData\Local\Temp\cckeVUNm.o:gluttest.cpp:(.text+0x3e): undefined reference to `_imp____glutCreateWindowWithExit@8'
C:\Users\Zachary\AppData\Local\Temp\cckeVUNm.o:gluttest.cpp:(.text+0x60): undefined reference to `_imp____glutCreateMenuWithExit@8'
C:\Users\Zachary\AppData\Local\Temp\cckeVUNm.o:gluttest.cpp:(.text+0xa0): undefined reference to `_imp__glutInitDisplayMode@4'
C:\Users\Zachary\AppData\Local\Temp\cckeVUNm.o:gluttest.cpp:(.text+0xb9): undefined reference to `_imp__glutInitWindowSize@8'
C:\Users\Zachary\AppData\Local\Temp\cckeVUNm.o:gluttest.cpp:(.text+0xd2): undefined reference to `_imp__glutMainLoop@0'
collect2: ld returned 1 exit status

我知道它可以找到头文件和库文件,因为如果我删除其中一个文件,它会给我一个错误,说它无法找到它们。我不确定从哪里开始。我曾尝试重新编译freeglut,但这似乎也不起作用。

有人提到添加-DFREEGLUT_STATIC以让它知道它是静态编译的。但是,我收到了同样的错误消息。

有什么建议吗?

根据答案到目前为止,我将编译命令改为

g++ gluttest.cpp -o gluttest -I/c/Libraries/glsdk_0.4.4/freeglut/include -L/c/Libraries/glsdk_0.4.4/freeglut/lib -DFREEGLUT_STATIC -D_LIB -DFREEGLUT_LIB_PRAGMAS=0 -lgdi32 -lwinmm -luser32 -lglu32 -lopengl32 -lfreeglut

但我仍然遇到同样的错误。

1 个答案:

答案 0 :(得分:0)

你需要实际link with the libraries-L只设置库路径。由于您没有使用提供的Premake4工具与库链接,因此您还必须设置上述页面上的说明中列出的定义。