将ZeroMQ交叉编译为ARM以用于MonoTouch iPhone应用程序configuration设置

我正在尝试在使用MonoTouch的C#开发的iPhone应用程序中使用ZeroMQ库。 我已经解决了几乎所有的问题,但最后的障碍已经落空了。 我正在使用ZeroMQ 2.1.10和C#CLR绑定/包装器,并在Mac OS X 10.6.8中进行开发。 这是迄今为止的故事:

我首先尝试在简单的Mono C#控制台应用程序中使用ZeroMq。 我用./configure构build了ZeroMQ,然后makesudo make install ,安装共享库/usr/local/lib/libzmq.dylib 。 ZeroMq C#绑定clrzmq.dll是一个包装,通过C Api [DllImport]调用使用“核心”ZeroMqfunction。

testing应用程序没有工作,我认为是标准的ZeroMQ ./configure产生一个64位的输出,单声道只有32位。 然后我重build了ZeroMQ

 ./configure CFLAGS="-O -arch i386" CXXFLAGS="-O -arch i386" LDFLAGS="-arch i386" --disable-dependency-tracking 

我简单的C#ZeroMq应用程序然后正常工作。

接下来,我尝试从iPhone模拟器中的iPhone应用程序中使用ZeroMq。 我发现iPhone只允许静态链接库(不允许dynamic库)。 这是通过改变所有的C#封装调用来实现的

 [DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)] 

并直接在MonoTouch项目中包含libzmq.a ,并设置额外的mtouch参数

 -cxx -gcc_flags "-L${ProjectDir} -lzmq -force_load ${ProjectDir}/libzmq.a" 

以确保ZeroMQ库包含在iPhone应用程序中。

当在iPhone模拟器中运行应用程序时,它崩溃了,我跟踪到从zmq_init()调用socketpair 。 我终于追溯到了ZeroMQ库,它是针对我的构build机器的MacOS头文件和库而build立的,而不是针对iPhone SDK。 这被修复了

 ./configure CFLAGS="-O -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk" CXXFLAGS="-O -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk" LDFLAGS="-arch i386" --disable-dependency-tracking 

在iPhone模拟器的成功! 模拟器需要为iPhone模拟器SDK构build的i386静态库。 我现在只能在模拟器的iPhone应用程序中使用ZeroMQfunction。 但是在真正的iPhone上它不起作用。

这是因为一个真正的iPhone需要一个为ARM架构而build立的库,而且是真正的iPhoneOS SDK。

(有一个侧面的问题,build立3个独立的库 – i386,ARM6,和ARM7,并将所有3结合到“胖”库,可以在任何环境中使用。我需要能够build立之前ARM这个问题)。

**最后,我的问题! **

最后一步是将编译ZeroMQ库交叉编译到ARM。 我一整天都在努力想出正确的开关,并且研究了我可以find的互联网上的所有例子,但似乎没有一个解决scheme可行。

我最近工作的是:

 ./configure CXX=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-g++-4.2 CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 LD=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld CFLAGS="-O -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk" CXXFLAGS="-O -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk" --disable-dependency-tracking --host=arm-apple-darwin10 LDFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk" 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 

这会产生一个编译ZeroMq代码的configuration,但会导致大量链接错误,例如:

 ar: libzmq_la-clock.o: No such file or directory 

我已经尝试了许多其他的configuration,但他们甚至没有正确传递./configure

任何人都可以帮助我一个合适的./configure参数列表来产生一个ARM架构静态库? 这就是我需要让ZeroMQ在真正的iPhone上工作的一切。

和所有帮助非常感谢!

只是以为我会分享,我最终find了答案 – 诀窍是添加CPP="cpp" CXXCPP="cpp"./configure语句,给:

 ./configure CPP="cpp" CXXCPP="cpp" CXX=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-g++-4.2 CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 LD=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld CFLAGS="-O -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk" CXXFLAGS="-O -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk" --disable-dependency-tracking --host=arm-apple-darwin10 LDFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk" 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 

我使用这个configuration成功地为ARM构build了ZeroMQ,就像我的新iPhone应用程序I Buzzed First(在http://itunes.apple.com/gb/app/i-buzzed-first//id490622820?mt=8

这个问题和MonoTouch没有什么关系,但是如何在iOS上编译0MQ(ARM)。 看看: 为iPhone编译C库

希望它会帮助你,也包括下一个问题:使用lipo胖通用二进制文件。 好消息是,如果这在模拟器上工作,那么你可能已经涵盖了任何与MonoTouch相关的问题:-)