autotools 在MAC上编译问题

通常在MAC上可以和其他linux机器一样用

autoreconf -vi && cd bin && ../configure && make

 但是在需要编译iOS(iPhone, AppleTV, WatchOS)之类的二进制文件时需要有其他的设置

-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk \
-mios-simulator-version-min=10.3

 这个是iPhone模拟器的设置,编译出来的结果可以给模拟器使用。

在模拟器上又对二进制文件有32位和64位的不同要求。以xcode 8.3.1为例,除iphone 5 要求32位外,其他全部要求64位。

如果分开做的话需要每次将下其中一个参数加入到编译选项中

// intel 32bits?
-arch i386

// amd64?
-arch x86_64

// powerpc 32bits
-arch ppc

// powerpc 64bits
-arch ppc64

但是其实,mac上有一个叫fat或universal 的二进制格式。

autoconf手册里有提到过可以串在一起直接做成fat/universal格式的。如下

./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
                 CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
                 CPP="gcc -E" CXXCPP="g++ -E"

 注意,在xcode 8.3.1上ppc和ppc64不被支持,需要去掉。

最后编译结果会是这样

.libs/libhelloworld.a: Mach-O universal binary with 2 architectures: [i386: current ar archive random library] [x86_64: current ar archive random library]
.libs/libhelloworld.a (for architecture i386):  current ar archive random library
.libs/libhelloworld.a (for architecture x86_64):        current ar archive random library

autoconf手册上原文说不能保证所有情况下都成产生fat/universal格式的二进制文件.

猜你喜欢

转载自chenqi210.iteye.com/blog/2370506