[英]Cannot get a simple freeglut test program to compile on windows
我下载了包含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
但是我仍然遇到同样的错误。
您实际上需要与库链接 。 -L
仅设置库路径。 由于未使用提供的Premake4工具与该库链接,因此还必须按照上述页面上的说明中的设置设置定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.