 |
 |
Compiling C++ OpenGL HOW??
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status:
Offline
|
|
Hey All,
I'm currently teaching myself C/C++ and OpenGL and I've got a few questions I was wondering if anyone could help me with. In order to compile any openGL programs, I've used the following command line (I'm writing these programs with bbedit):
cc -framework OpenGL -framework GLUT -lobjc *.c
Now, I can change the last bit to *.cpp but either way, it won't compile any C++ code, because of the -lobjc. Does anyone know how to compile C++ code with opengl? If I simply:
cpp *.cpp
then it can't find the OpenGL libraries and such. How do I link them together? Thanks,
Gabe
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
You may want to try c++ rather than cpp. cpp is the C preprocessor, afaik.
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
I think you're a little confused. In the first example, you're linking in the Objective-C library. In the second example, it looks like you're sending the code to the preprocessor. Neither of these is particularly germane to linking in OpenGL. I'd think it should look more like this:
c++ -framework OpenGL -framework GLUT *.cpp
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status:
Offline
|
|
Thanks for your replies. Still no dice though. I tried the following:
c++ -framwork OpenGL -framework GLUT main.cpp and I got back this:
/usr/bin/ld: /usr/lib/crt1.o illegal reference to symbol: __objcInit defined in indirectly referenced dynamic library /usr/lib/libobjc.A.dylib
Here's my program if you'd like to see it:
#include <GLUT/glut.h>
#include <stdlib.h>
#define PI 3.1415926535898
void idle(void);
GLdouble move = 0.1;
GLdouble xLook = 0;
void init(void){
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glLoadIdentity();
gluLookAt(0.0,0.0,5.0,xLook,0.0,0.0,0.0,1.0,0.0);
glScalef(1.0,2.0,1.0);
glutWireCube(1.0);
glFlush();
}
void reshape(int w, int h){
glViewport(0,0,(GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(-50.0,50.0,-50.0,50.0,-1.0,1.0);
glFrustum(-1.0,1.0,-1.0,1.0,1.5,20.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(250,250);
glutInitWindowPosition(600,200);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}
void idle(void){
if (xLook > 10.0 || xLook < -10.0)
move *= -1;
xLook += move;
glutPostRedisplay();
}
any ideas? Thanks,
Gabe
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
c++ -framework OpenGL -framework GLUT -lobjc main.cpp worked for me.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2001
Location: Bethesda, MD
Status:
Offline
|
|
I think you need "-framework Foundation" too.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status:
Offline
|
|
Thanks you guys! The following seemed to work for me:
c++ -framework OpenGL -framework GLUT -lobjc
What does the -framework Foundation do? It compiled fine, and ran the same with or without it.
Oh, and does anyone know what will compile this into a double clickable application? Is that more complicated? Right now it makes a file called a.out and then I
./a.out
to run my programs. Any advice on how to make a double clickable one? Thanks,
Gabe
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
Originally posted by Zimwy:
Oh, and does anyone know what will compile this into a double clickable application?
Application bundles all have a specific format; looking through the system at various apps will give you an idea of how to manually create one.
However, the easiest way by far would be to just create your application in Project Builder. It will generate the application bundle for you. Create a new Carbon Application project, and then delete the automatically-generated main.h, main.c, and main.r files ("Delete References & Files"). Also remove the references to Carbon.framework, ApplicationServices.framework, and CoreServices.framework. This will leave you with a basic C++ application shell.
Create a new C++ file (e.g. main.cpp) for your code, and then add the OpenGL and GLUT frameworks (Project -> Add Frameworks...). Go into the Targets tab on the left and select the target listed. Click on the Build Settings tab that appears on the right, go to the Linker Settings section, and add "-lobjc" in the Other Linker Flags box. That should take care of everything you need to get this up and running.
If you want, you can create a custom .icns file and add it to your project's resources. Then go to the Application Settings tab of the target and type its name in the Icon File box.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|