views:

52

answers:

2

I am developing a program on OSX 10.6.4 (Snow Leopard), and I want to be able to run the compiled product on other Intel Macs, some of whom may not have XCode isntalled.

To simplify things, I first wrote a Hello World program.

#include<stdio.h>
int main() {
    printf("Hello world!\n");
    return 0;
}

If I compile it as

gcc -static prog.c

I get the folllowing error:

ld: library not found for -lcrt0.o

I don't know where to find this library. Now, some people have mentioned that I should not compile statically on macs since the system shared libraries should be available everywhere (third party libraries can be manually linked). However, when I try to run this Hello World program on another mac, I get the folowing error:

 dyld: unknown required load command 0x80000022
 Trace/BPT trap

So, how do you compile a program on mac so that it can be distributed? I am not having architecture issues, as most computers I am interested in are Intel Macs.

+1  A: 

Don't use -static. Your executable will run fine on other 10.6.x x86 Macs. If you want to deploy on pre-10.6 Macs then you'll need to use the appropriate SDK but apart from that it should "just work", regardless of whether the developer tools are installed.

Paul R
I tried to compile as gcc prog.c -isysroot /Developer/SDKs/MacOSX10.5.sdkHowever, it still givesdyld: unknown required load command 0x80000022Trace/BPT trapon an older machine. Is this how one uses the SDK?
highBandWidth
Ok so it works for the Hello world program after adding -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 to the gcc command line. However, for a C++ program it needs certain tr2 implementations introduced in 10.6, and it doesn't compile with that SDK. It compiles if I use the macports gcc, but then when running on another computer it fails to find a function in /ust/lib/libstdc++.6.dylib.
highBandWidth
If you have a dependency on 10.6 then obviously your executable will not run on 10.5.
Paul R
@Paul R agreed!
highBandWidth
+1  A: 

It might be worth using XCode to create your executable, using the Command Line program template (basic Unix executables), simply because it will manage a lot of the compiler options for you (including which SDK you are compiling against / which versions you are targeting).

My guess is that a default commmand-line compilation is going to compile against the current system libraries (10.6.4).

JulesLt