eclipse 上 openGl 的问题
我正在使用 Windows XP,我有 Eclipse Galileo 的便携式版本,但我没有发现太多,所以我决定使用这个 link 我完成了所有步骤,现在我正在尝试编译此代码
#include "GL/glut.h"
#include "GL/gl.h"
#include "GL/glu.h"
///////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);
// Flush drawing commands
glFlush();
}
///////////////////////////////////////////////////////////
// Setup the rendering state
void SetupRC(void)
{
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}
///////////////////////////////////////////////////////////
// Main program entry point
void main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(800,600);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);
SetupRC();
glutMainLoop();
}
,但出现此错误
Simple.o: In function `RenderScene':
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:16: undefined reference to `_imp__glClear'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:20: undefined reference to `_imp__glFlush'
Simple.o: In function `SetupRC':
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:27: undefined reference to `_imp__glClearColor'
Simple.o: In function `main':
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:34: undefined reference to `glutInit'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:35: undefined reference to `glutInitDisplayMode'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:36: undefined reference to `glutInitWindowSize'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:37: undefined reference to `glutCreateWindow'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:38: undefined reference to `glutDisplayFunc'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:42: undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status
,请有人帮忙我,提前谢谢
I'm working on Windows XP I have portable version of Eclipse Galileo, but I didn't find there glut so I decided to add it using this link I made all steps and and now I'm trying to compile this code
#include "GL/glut.h"
#include "GL/gl.h"
#include "GL/glu.h"
///////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);
// Flush drawing commands
glFlush();
}
///////////////////////////////////////////////////////////
// Setup the rendering state
void SetupRC(void)
{
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}
///////////////////////////////////////////////////////////
// Main program entry point
void main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(800,600);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);
SetupRC();
glutMainLoop();
}
and I have this errors
Simple.o: In function `RenderScene':
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:16: undefined reference to `_imp__glClear'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:20: undefined reference to `_imp__glFlush'
Simple.o: In function `SetupRC':
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:27: undefined reference to `_imp__glClearColor'
Simple.o: In function `main':
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:34: undefined reference to `glutInit'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:35: undefined reference to `glutInitDisplayMode'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:36: undefined reference to `glutInitWindowSize'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:37: undefined reference to `glutCreateWindow'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:38: undefined reference to `glutDisplayFunc'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:42: undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status
please can somebody help me, thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎错过了添加库并且链接器找不到它们。确保在“库”对话框中指定了正确的库。我这里没有安装 Eclipse,但该对话框应该位于“右键单击项目 -> ”附近的某个位置。属性->库/C++ 链接器”
It seems that you have missed to add the libraries and the linker cannot find them. Make sure that the correct libraries are specified in the Libraries dialog. I don't have a Eclipse installation here but this dialog should be somewhere around `Right click project -> Properties -> Libraries/C++ Linker"
看来您没有链接 OpenGL、GLU 或 GLUT 库。您需要告诉 Eclipse 链接它们,并且需要告诉它存储它们的目录(至少对于大多数 IDE,这两个操作是相互独立的)。
如果没记错的话,openGL 本身就是 opengl32.lib。如果开始时安装合理,IDE 可能已经知道该库的位置(即,它是 Windows 的正常部分,并且该库将与其他正常 Windows 库一起)。
glu
函数位于 glu32.lib 中,它们应该位于同一位置。Glut 通常位于名为 glut32.lib 的文件中。假设您将 Glut 安装在 C 驱动器的根目录中,它通常位于“C:\glut-3.7\lib\glut”。
It looks like you're not linking the OpenGL, GLU or GLUT libraries. You need to tell Eclipse to link them, and you need to tell it the directories where they're stored (at least with most IDEs, the two operations are separate from each other).
If memory serves, openGL itself will be opengl32.lib. If it installed reasonably to start with, the IDE will probably already know the location for this library (i.e., it's a normal part of Windows, and the library will be along with the other normal Windows libraries). The
glu
functions are in glu32.lib, which should be in the same place.Glut will normally be in a file named glut32.lib. Assuming you installed Glut in the root directory of your C drive, it would typically be at "C:\glut-3.7\lib\glut".