2010-08-31 54 views
4

我想要編譯ZeroMQ C語言綁定,以便能夠使用它在iPhone上,這裏是我的配置選項:編譯C LIB爲iPhone

./configure --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-gcc-4.2.1 CFLAGS="-pipe -std=c99 -Wno-trigraphs -fpascal-strings -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=3.1.2 -gdwarf-2 -mthumb -I/Library/iPhone/include -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk -mdynamic-no-pic" CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar AS=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/as LIBTOOL=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool STRIP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/strip RANLIB=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ranlib

它實際上是配置和編譯罰款,但是當我將它添加到Xcode Frameworks部分時,我得到警告:ld: warning: in /path/to/app/libzmq.a, file was built for unsupported file format which is not the architecture being linked (armv7)和很多符號未找到錯誤。

如果我將當前活動架構從armv6更改爲armv7,則警告消息會將其更改爲armv6。 我在做什麼錯?

感謝, 丹

回答

6

這聽起來像你正在構建爲iPhone通用的ARMv6/ARMv7的二進制文件(這是默認的,這樣纔有意義)。這意味着你需要建立一個通用庫來鏈接。建立兩個庫,然後用lipo來結合這兩個。

例如,構建armv6並將其放置在armv6/libfoo.a處,並將armv7放置在armv7/libfoo.a處。然後運行

lipo -arch armv6 armv6/libfoo.a -arch armv7 armv7/libfoo.a -output libfoo.a -create 

創建通用庫libfoo.a

+0

感謝您的回答,但我如何定義架構? arm-apple-darwin10-gcc-4.2.1不支持-arch選項。 順便說一句,lipo -info爲我的lib說,編譯爲x86_64,這是奇怪的。 – Dan 2010-09-01 20:39:00

+0

對不起,我沒有注意到你沒有通過'-arch'選項。我不確定它爲什麼不接受它,但爲什麼不嘗試使用'/ Developer/Platforms /.../ gcc'呢?我只是查找了我用過的C庫的配置命令,而且經常可以工作。 – 2010-09-01 21:12:45

+2

謝謝,我終於能夠使用這個問題的腳本進行編譯了 - http://stackoverflow.com/questions/1602182/cross-compile-autotools-based-libraries-for-official-iphone-sdk – Dan 2010-09-02 18:41:04

0

鑑於從ld警告消息,我的猜測是你不編譯正確的平臺庫。考慮到你使用的是configure,我的猜測是你試圖編譯Xcode之外的庫,然後將它帶入Xcode以便將其鏈接到它。

也許你可以嘗試運行configure來設置你的頭文件,但在Xcode中做實際的編譯步驟?

關於編譯用於iPhone項目的第三方(外部)C或C++庫,這裏有很多關於SO的相關問題。

Creating static library for iPhone

TiMidity: need help compiling this library for the iPhone

+0

目前,我發現編譯多種體系結構庫的最佳指南是:http://tinsuke.wordpress.com/2011/02/17/how-to-cross-compiling-libraries-for-ios-armv6armv7i386/ – Alper 2012-08-12 10:21:04