Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top