gpt4 book ai didi

windows - 无法在 Windows 上编译一个简单的 freeglut 测试程序

转载 作者:可可西里 更新时间:2023-11-01 10:48:09 29 4
gpt4 key购买 nike

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

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

最佳答案

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

关于windows - 无法在 Windows 上编译一个简单的 freeglut 测试程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15318167/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com