|
|
GLUT and Mac OS X
|
|
|
|
Fresh-Faced Recruit
Join Date: Nov 2002
Location: Cambridge, MA
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Nov 2002
Location: Cambridge, MA
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Apr 2001
Location: Bethesda, MD
Status:
Offline
|
|
Add "-lobjc" to your link line.
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Nov 2002
Location: Cambridge, MA
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Apr 2002
Location: France
Status:
Offline
|
|
You need to add -lobjc because the display is made via the AppKit.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
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'."
|
|
|
|
|
|
|
|
Junior Member
Join Date: Jun 2001
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Nov 2000
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Junior Member
Join Date: Jun 2001
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2002
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
Junior Member
Join Date: Jun 2001
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2002
Status:
Offline
|
|
The C preprocessor on SunOS must not be called cpp, then.
|
[vash:~] banana% killall killall
Terminated
|
|
|
|
|
|
|
|
Junior Member
Join Date: Jun 2001
Status:
Offline
|
|
When I change it to a c preprocessor such as cc, gcc, or g++ I get a "Compilation of header file requested" error
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2002
Status:
Offline
|
|
Those aren't preprocessors, they are compilers.
|
[vash:~] banana% killall killall
Terminated
|
|
|
|
|
|
|
|
Junior Member
Join Date: Jun 2001
Status:
Offline
|
|
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 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
|
|
|
|
|
|
|
|
|
|
|
|