I have been trying to setup the OpenGL and GLUT libraries in Eclipse, with CDT, on OS X with not very much success. I cannot seem to get eclipse to actually realize where GLUT is. It is currently giving me the error that I have an unresolved inclusion GL/glut.h. Looking around online I found that I should be using the -framework GLUT flag in the gcc linker settings, but this seems ineffective.
我一直试图在Eclipse中使用CDT在OS X上安装OpenGL和供过于求的库,但没有取得太大的成功。我似乎无法让eclipse真正意识到过剩在哪里。目前它给我的错误是我有一个未解决的包含GL/glut.h。我在网上查了一下,发现我应该在gcc链接器设置中使用-framework供过于求标志,但这似乎是无效的。
4 个解决方案
#1
7
Ok. I got it working in X11. The reason I could only get it working on X11 is because it seems the OpenGL libs on the OS are for the 64-bit architecture, but eclipse will only compile code if we use 32-bit architecture. Maybe if this got fixed we could use OS X pre-installed libraries. Also, maybe there is a 32-bit version lying around on the OS we could use that but I can't seem to find it. I, however, am content with using X11 for my learning purposes.
好的。我让它在X11中工作。我之所以能够在X11上工作是因为在OS上的OpenGL libs是用于64位架构的,但是如果我们使用32位架构,eclipse只会编译代码。如果这个问题得到解决,我们可以使用OS X预安装库。另外,在操作系统上可能有一个32位的版本,我们可以使用它,但是我似乎找不到它。然而,出于学习目的,我对使用X11很满意。
First create your C++ project. Then since you can't compile code in 64-bit using eclipse add the following...
首先创建您的c++项目。既然不能使用eclipse编译64位代码,那么添加以下内容……
alt text http://img132.imageshack.us/img132/5163/step1c32bit.png
alt文本http://img132.imageshack.us/img132/5163/step1c32bit.png
alt text http://img251.imageshack.us/img251/5163/step1c32bit.png
alt文本http://img251.imageshack.us/img251/5163/step1c32bit.png
alt text http://img132.imageshack.us/img132/2325/step1linker32bit.png
alt文本http://img132.imageshack.us/img132/2325/step1linker32bit.png
Then you need your libraries and linking set up. To do this do the following:
然后需要设置库和链接。要做到这一点,要做到以下几点:
alt text http://img29.imageshack.us/img29/1904/step2linkerglglu.png
alt文本http://img29.imageshack.us/img29/1904/step2linkerglglu.png
alt text http://img196.imageshack.us/img196/4313/step2glut.png
alt文本http://img196.imageshack.us/img196/4313/step2glut.png
Lastly you need to set a DISPLAY variable.
最后,需要设置一个显示变量。
alt text http://img40.imageshack.us/img40/7306/step3display.png
alt文本http://img40.imageshack.us/img40/7306/step3display.png
Before you try running start up X11.
在您尝试运行之前,先启动X11。
Try the following code to get something I've got running in my machine. Hope it works for you!
尝试以下代码来获取我在机器中运行的一些东西。希望它对你有用!
//#include <GL/gl.h>
//#include <GL/glu.h>
#include <GL/glut.h>
#define window_width 640
#define window_height 480
// Main loop
void main_loop_function() {
// Z angle
static float angle;
// Clear color (screen)
// And depth (used internally to block obstructed objects)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Load identity matrix
glLoadIdentity();
// Multiply in translation matrix
glTranslatef(0, 0, -10);
// Multiply in rotation matrix
glRotatef(angle, 0, 0, 1);
// Render colored quad
glBegin( GL_QUADS);
glColor3ub(255, 000, 000);
glVertex2f(-1, 1);
glColor3ub(000, 255, 000);
glVertex2f(1, 1);
glColor3ub(000, 000, 255);
glVertex2f(1, -1);
glColor3ub(255, 255, 000);
glVertex2f(-1, -1);
glEnd();
// Swap buffers (color buffers, makes previous render visible)
glutSwapBuffers();
// Increase angle to rotate
angle += 0.25;
}
// Initialze OpenGL perspective matrix
void GL_Setup(int width, int height) {
glViewport(0, 0, width, height);
glMatrixMode( GL_PROJECTION);
glEnable( GL_DEPTH_TEST);
gluPerspective(45, (float) width / height, .1, 100);
glMatrixMode( GL_MODELVIEW);
}
// Initialize GLUT and start main loop
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitWindowSize(window_width, window_height);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("GLUT Example!!!");
glutDisplayFunc(main_loop_function);
glutIdleFunc(main_loop_function);
GL_Setup(window_width, window_height);
glutMainLoop();
}
#2
3
Depending on which GLUT library you installed in OS X your include might be different.
根据您在OS X中安装的过剩库的不同,您的包含可能有所不同。
On my system I have to use:
在我的系统上,我必须使用:
#include <GLUT/glut.h>
To make sure my code is cross platform I use the following pre-processor statement:
为了确保我的代码是跨平台的,我使用了以下预处理语句:
#if defined(__APPLE__) && defined(__MACH__)
# include <GLUT/glut.h>
#else
# include <GL/glut.h>
#endif
That might fix some or your problems.
这可能会解决你的一些问题。
#3
2
I wrote an article about how to setup Eclipse to develop OpenGL (and GLUT) applications in C/C++ and Java in both Windows and Mac OS X if you are interested. It contains all the steps and all you need to know to have the system ready.
我写了一篇文章,介绍如何在Windows和Mac OS X中使用C/ c++和Java开发OpenGL(以及过剩)应用程序。它包含了准备系统所需的所有步骤和所有信息。
You can find it here:
Setup Eclipse to develop OpenGL & GLUT apps in Java & C/C++ on Windows & MAC OS X!
您可以在这里找到它:安装Eclipse,在Windows和MAC OS X上开发OpenGL和过剩的Java和C/ c++应用程序!
#4
1
The default install directory for MacPorts is /opt/local. Could be /opt/local isn't added to your compiler include path in Eclipse. Either that, or reinstalling Xcode to give you GLUT/glut.h on the default include path for Xcode libs (which you may then need to add to eclipse? I don't run OS X so I can't say what the Xcode installdir is, but it looks like it could be in /Developer, or /Library/Developer/Shared).
MacPorts的默认安装目录是/opt/local。可能是/opt/local没有添加到Eclipse的编译器include路径中。要么这样,要么重新安装Xcode,让您产生过剩/过剩。h在Xcode libs的默认包含路径(然后您可能需要将其添加到eclipse?我不运行OS X,所以我不能说出Xcode installdir是什么,但它看起来可能是在/Developer、或/Library/Developer/Shared中。
#1
7
Ok. I got it working in X11. The reason I could only get it working on X11 is because it seems the OpenGL libs on the OS are for the 64-bit architecture, but eclipse will only compile code if we use 32-bit architecture. Maybe if this got fixed we could use OS X pre-installed libraries. Also, maybe there is a 32-bit version lying around on the OS we could use that but I can't seem to find it. I, however, am content with using X11 for my learning purposes.
好的。我让它在X11中工作。我之所以能够在X11上工作是因为在OS上的OpenGL libs是用于64位架构的,但是如果我们使用32位架构,eclipse只会编译代码。如果这个问题得到解决,我们可以使用OS X预安装库。另外,在操作系统上可能有一个32位的版本,我们可以使用它,但是我似乎找不到它。然而,出于学习目的,我对使用X11很满意。
First create your C++ project. Then since you can't compile code in 64-bit using eclipse add the following...
首先创建您的c++项目。既然不能使用eclipse编译64位代码,那么添加以下内容……
alt text http://img132.imageshack.us/img132/5163/step1c32bit.png
alt文本http://img132.imageshack.us/img132/5163/step1c32bit.png
alt text http://img251.imageshack.us/img251/5163/step1c32bit.png
alt文本http://img251.imageshack.us/img251/5163/step1c32bit.png
alt text http://img132.imageshack.us/img132/2325/step1linker32bit.png
alt文本http://img132.imageshack.us/img132/2325/step1linker32bit.png
Then you need your libraries and linking set up. To do this do the following:
然后需要设置库和链接。要做到这一点,要做到以下几点:
alt text http://img29.imageshack.us/img29/1904/step2linkerglglu.png
alt文本http://img29.imageshack.us/img29/1904/step2linkerglglu.png
alt text http://img196.imageshack.us/img196/4313/step2glut.png
alt文本http://img196.imageshack.us/img196/4313/step2glut.png
Lastly you need to set a DISPLAY variable.
最后,需要设置一个显示变量。
alt text http://img40.imageshack.us/img40/7306/step3display.png
alt文本http://img40.imageshack.us/img40/7306/step3display.png
Before you try running start up X11.
在您尝试运行之前,先启动X11。
Try the following code to get something I've got running in my machine. Hope it works for you!
尝试以下代码来获取我在机器中运行的一些东西。希望它对你有用!
//#include <GL/gl.h>
//#include <GL/glu.h>
#include <GL/glut.h>
#define window_width 640
#define window_height 480
// Main loop
void main_loop_function() {
// Z angle
static float angle;
// Clear color (screen)
// And depth (used internally to block obstructed objects)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Load identity matrix
glLoadIdentity();
// Multiply in translation matrix
glTranslatef(0, 0, -10);
// Multiply in rotation matrix
glRotatef(angle, 0, 0, 1);
// Render colored quad
glBegin( GL_QUADS);
glColor3ub(255, 000, 000);
glVertex2f(-1, 1);
glColor3ub(000, 255, 000);
glVertex2f(1, 1);
glColor3ub(000, 000, 255);
glVertex2f(1, -1);
glColor3ub(255, 255, 000);
glVertex2f(-1, -1);
glEnd();
// Swap buffers (color buffers, makes previous render visible)
glutSwapBuffers();
// Increase angle to rotate
angle += 0.25;
}
// Initialze OpenGL perspective matrix
void GL_Setup(int width, int height) {
glViewport(0, 0, width, height);
glMatrixMode( GL_PROJECTION);
glEnable( GL_DEPTH_TEST);
gluPerspective(45, (float) width / height, .1, 100);
glMatrixMode( GL_MODELVIEW);
}
// Initialize GLUT and start main loop
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitWindowSize(window_width, window_height);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("GLUT Example!!!");
glutDisplayFunc(main_loop_function);
glutIdleFunc(main_loop_function);
GL_Setup(window_width, window_height);
glutMainLoop();
}
#2
3
Depending on which GLUT library you installed in OS X your include might be different.
根据您在OS X中安装的过剩库的不同,您的包含可能有所不同。
On my system I have to use:
在我的系统上,我必须使用:
#include <GLUT/glut.h>
To make sure my code is cross platform I use the following pre-processor statement:
为了确保我的代码是跨平台的,我使用了以下预处理语句:
#if defined(__APPLE__) && defined(__MACH__)
# include <GLUT/glut.h>
#else
# include <GL/glut.h>
#endif
That might fix some or your problems.
这可能会解决你的一些问题。
#3
2
I wrote an article about how to setup Eclipse to develop OpenGL (and GLUT) applications in C/C++ and Java in both Windows and Mac OS X if you are interested. It contains all the steps and all you need to know to have the system ready.
我写了一篇文章,介绍如何在Windows和Mac OS X中使用C/ c++和Java开发OpenGL(以及过剩)应用程序。它包含了准备系统所需的所有步骤和所有信息。
You can find it here:
Setup Eclipse to develop OpenGL & GLUT apps in Java & C/C++ on Windows & MAC OS X!
您可以在这里找到它:安装Eclipse,在Windows和MAC OS X上开发OpenGL和过剩的Java和C/ c++应用程序!
#4
1
The default install directory for MacPorts is /opt/local. Could be /opt/local isn't added to your compiler include path in Eclipse. Either that, or reinstalling Xcode to give you GLUT/glut.h on the default include path for Xcode libs (which you may then need to add to eclipse? I don't run OS X so I can't say what the Xcode installdir is, but it looks like it could be in /Developer, or /Library/Developer/Shared).
MacPorts的默认安装目录是/opt/local。可能是/opt/local没有添加到Eclipse的编译器include路径中。要么这样,要么重新安装Xcode,让您产生过剩/过剩。h在Xcode libs的默认包含路径(然后您可能需要将其添加到eclipse?我不运行OS X,所以我不能说出Xcode installdir是什么,但它看起来可能是在/Developer、或/Library/Developer/Shared中。