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 > GLUT and Mac OS X

GLUT and Mac OS X
Thread Tools
cello
Fresh-Faced Recruit
Join Date: Nov 2002
Location: Cambridge, MA
Status: Offline
Reply With Quote
Nov 12, 2002, 10:50 PM
 
I'm trying to create a cross-platform (linux and mac os x) application that uses glut and openGL. I installed the glut framework by building the code from the apple developer's site (sample code) and putting it in my frameworks folder. I've tried using both project builder and the command line to create the application. The code is pretty simple:

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>

#define _LINUX_ 0


// include files from the frameworks
#if _LINUX_
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#else
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#endif

int main(int argc, char* argv[])
{

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow( "test" );
glutMainLoop();

return 0;
}

Then, I typed the following in the command line:
gcc -framework OpenGL -framework GLUT main.cpp

and recieved the following error:
ld: /usr/lib/crt1.o illegal reference to symbol: __objcInit defined in indirectly referenced dynamic library /usr/lib/libobjc.A.dylib

It seems as though it's fooling around with some objective c thing �_I'm not really sure what to do about this.

Using project builder, it builds, yet then it says that there are no executables to run. I tried to see if it actually created an executable, and it did. However, running that executable (created by project builder) through the command line told me that it was a "bad executable."

It would be great if you have any suggestions regarding simply GLUT and mac os x as well, since I have never used GLUT before.
     
Detrius
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status: Offline
Reply With Quote
Nov 13, 2002, 12:11 AM
 
To appease the compiler's objective-c interests, simply rename your file from main.cpp to main.mm, and try compiling again. The .mm ending says that you are using objective-c++ so you can se Objective-C and C++ within the same code files and it will still compile... it's really cool. I use it all the time.
ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
cello  (op)
Fresh-Faced Recruit
Join Date: Nov 2002
Location: Cambridge, MA
Status: Offline
Reply With Quote
Nov 13, 2002, 12:20 AM
 
The code isn't written in objective c, it's in C++ entirely. Anyhow, making this change doesn't affect the problem �_I still get the same strange error message when it tries to link.

ld: /usr/lib/crt1.o illegal reference to symbol: __objcInit defined in indirectly referenced dynamic library /usr/lib/libobjc.A.dylib
     
davechen
Dedicated MacNNer
Join Date: Apr 2001
Location: Bethesda, MD
Status: Offline
Reply With Quote
Nov 13, 2002, 12:54 AM
 
Add "-lobjc" to your link line.
     
cello  (op)
Fresh-Faced Recruit
Join Date: Nov 2002
Location: Cambridge, MA
Status: Offline
Reply With Quote
Nov 13, 2002, 01:22 AM
 
Well, I finally got it to work_�_though for some reason I needed to use g++ rather than gcc. Anyhow, why would I need to add the -lobjc flag, especially since I'm not even dealing with objective c? Is this just some mac os x quirk, or is there an actual specific reason behind it?
     
reversi
Fresh-Faced Recruit
Join Date: Apr 2002
Location: France
Status: Offline
Reply With Quote
Nov 14, 2002, 09:15 AM
 
You need to add -lobjc because the display is made via the AppKit.
     
Detrius
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status: Offline
Reply With Quote
Nov 15, 2002, 02:42 AM
 
Originally posted by cello:
Well, I finally got it to work_�_though for some reason I needed to use g++ rather than gcc. Anyhow, why would I need to add the -lobjc flag, especially since I'm not even dealing with objective c? Is this just some mac os x quirk, or is there an actual specific reason behind it?
I was under the impression that gcc didn't even do c++, so for a .cpp file, you would need to use g++ anyway.

The -lobjc flag is because the library you are using relies on stuff that's in the objective-c libraries.
ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Nov 15, 2002, 03:24 PM
 
Originally posted by Detrius:


I was under the impression that gcc didn't even do c++, so for a .cpp file, you would need to use g++ anyway.
G++ is GCC. GCC is the GNU Compiler Collection, which works on C, C++ and Objective-C. Running it as G++ just runs GCC with certain options enabled.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
asidrane
Junior Member
Join Date: Jun 2001
Status: Offline
Reply With Quote
Mar 8, 2003, 03:01 PM
 
Does:
"#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>

#define _LINUX_ 0


// include files from the frameworks
#if _LINUX_
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#else
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#endif
"
work? I too am trying to do development on two systems (OS X and SunOS) and it would be nice to get the code to choose includes based on the OS to work. From wat I can tell, the code will always include the else part of the statement, meaning it will fail to compile on a Linux box. How do I get this to work? Thanks.
     
int69h
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Mar 8, 2003, 11:03 PM
 
Code:
#if defined(__APPLE__) /* Apple specific stuff */ #elif defined(__SOLARIS__) /* Solaris specific stuff. Check cpp -dM for the correct define. */ #elif defined(__linux__) /* Linux specific stuff */ #else Error! This software has not been ported to this platform. #endif
You can use touch foo.h && cpp -dM foo.h to find out what gcc is defining for your platform.
     
asidrane
Junior Member
Join Date: Jun 2001
Status: Offline
Reply With Quote
Mar 10, 2003, 06:01 PM
 
Could you explain what you mean by this line a little more fully?

You can use touch foo.h && cpp -dM foo.h to find out what gcc is defining for your platform.
     
Gul Banana
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Mar 10, 2003, 10:17 PM
 
The command "touch foo.h && cpp -dM foo.h" will return a list like this:
Code:
#define __MACH__ 1 #define __POWERPC__ 1 #define __NATURAL_ALIGNMENT__ 1 #define __STDC_HOSTED__ 1 #define __NO_INLINE__ 1 #define __APPLE__ 1 #define __ppc__ 1 #define __GNUC__ 1 #define __DYNAMIC__ 1 #define __BIG_ENDIAN__ 1
This will allow you to see what gcc defines for your platform. For example, you can see that #ifdef __APPLE__ && #ifdef __GNUC__ you pretty much have to be running on OS X.
[vash:~] banana% killall killall
Terminated
     
asidrane
Junior Member
Join Date: Jun 2001
Status: Offline
Reply With Quote
Mar 11, 2003, 12:21 AM
 
Thanks, that works great. Funny thing is, the command worked on Darwin, but not on SunOS. It gave me an error that cpp isn't a command.
     
Gul Banana
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Mar 11, 2003, 12:29 AM
 
The C preprocessor on SunOS must not be called cpp, then.
[vash:~] banana% killall killall
Terminated
     
asidrane
Junior Member
Join Date: Jun 2001
Status: Offline
Reply With Quote
Mar 11, 2003, 03:15 AM
 
When I change it to a c preprocessor such as cc, gcc, or g++ I get a "Compilation of header file requested" error
     
Gul Banana
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Mar 12, 2003, 05:59 AM
 
Those aren't preprocessors, they are compilers.
[vash:~] banana% killall killall
Terminated
     
asidrane
Junior Member
Join Date: Jun 2001
Status: Offline
Reply With Quote
Mar 12, 2003, 06:01 PM
 
Right. I got this whol emess straightened out. I didn't think any of those options would work,but it was worth a shot. The c preprocessor on my sun machine doesn't support the -dM option.
     
   
 
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
Top
Privacy Policy
All times are GMT -4. The time now is 11:09 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,