views:

105

answers:

3

I have some c++ code compiled using GLUT and OpenGL on os x. It all works fine. I have it as a.out

Is there a way to send this to someone using os x? Will there be some weird dependencies? Can I send it to someone using linux?

I doubt I can do either which is why I'm asking on here. I looked around on google but couldn't find anything useful, I'm probably not searching for the right stuff

thanks

+10  A: 

OS X and Linux have completely different binary formats (Mach-O/Universal Binary and ELF respectively), so no, a program compiled on OS X won't run on Linux unless you cross-compiled it.

If you compiled your code using static linking, then another OS X user will be able to use it just fine. However, bearing in mind that I know very little about GLUT or OpenGL, I'd bet good money that those are dynamic libraries, and thus whoever you send it to will need to have the same libraries installed in the same place in order to be able to use your compiled code.

otool -L will display the linkage dependencies of your executable, FYI.

Meredith L. Patterson
I think many libraries are provided as both static and dynamic on OS X, so you might be able to get a static build out of them.
Chris Lutz
A: 

What about just sharing the source?

Are you afraid somebody's going to steal your precious work?

Sneakyness
What if the other person isn't a developer and wouldn't know a compiler if it bit them?
Meredith L. Patterson
Seriously. This isn't a put down. When people start taking your code you're doing something right.
Sneakyness
Oh, I agree with you - that wasn't my downvote. OTOH, my question still stands.
Meredith L. Patterson
Tell them to come over. Have them VNC into your system or use iChat's screen sharing. Take screenshots. There is no magical way to do this that is going to "just work".
Sneakyness
no worries, just didn't wanna have to install gcc developer stuff on their computer. Not to mention it'd be nice if they could just run it
Ori Cohen
+1  A: 

It should work to send it to someone using the same version of OS X and the same computer chip as you. It may even be possible on OS X to cross-compile to a universal binary that works on Intel and PowerPC chips, but you'll still be limited to OS X.

To get a working executable for Linux, you'll need to compile it on Linux (or use a cross-compiler, but that could be more difficult than it's worth, especially if you have to do it repeatedly).

Or, as has been said already, you could just distribute the source code and let people compile it themselves. This may be the best approach, because C++ has no common binary format, so if different people use different compilers that have different forms of name-mangling, they'll all still get a program that works (if they compiled OpenGL or GLUT with one C++ compiler and then you compiled your program with another, they might not work together (I think)).

Chris Lutz