【问题标题】:Cannot get a simple freeglut test program to compile on windows无法在 Windows 上编译一个简单的 freeglut 测试程序
【发布时间】:2013-03-10 02:13:35
【问题描述】:

我下载了包含 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

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

【问题讨论】:

    标签: windows opengl freeglut


    【解决方案1】:

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

    【讨论】:

    • 根据那里的说明,我更改了 g++ 命令。我把它放在上面的编辑中。但我遇到了同样的错误。
    猜你喜欢
    • 2019-05-07
    • 2020-11-13
    • 1970-01-01
    • 2021-03-18
    • 2021-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多