Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Compiling C++ OpenGL HOW??

Compiling C++ OpenGL HOW??
Thread Tools
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status: Offline
Reply With Quote
Aug 11, 2002, 12:23 AM
 
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
Reply With Quote
Aug 11, 2002, 01:58 AM
 
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
Reply With Quote
Aug 11, 2002, 02:19 AM
 
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'."
     
Zimwy  (op)
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status: Offline
Reply With Quote
Aug 11, 2002, 11:32 AM
 
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
Reply With Quote
Aug 11, 2002, 02:50 PM
 
c++ -framework OpenGL -framework GLUT -lobjc main.cpp worked for me.
     
Dedicated MacNNer
Join Date: Apr 2001
Location: Bethesda, MD
Status: Offline
Reply With Quote
Aug 11, 2002, 08:58 PM
 
I think you need "-framework Foundation" too.
     
Zimwy  (op)
Dedicated MacNNer
Join Date: May 2002
Location: Brooklyn, NY
Status: Offline
Reply With Quote
Aug 11, 2002, 10:20 PM
 
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
Reply With Quote
Aug 12, 2002, 12:15 PM
 
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.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:09 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2