开发者

How to compile a program for distribution on Mac

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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜