将 ZeroMQ 交叉编译到 ARM 以在 MonoTouch iPhone 应用程序配置设置中使用 [英] Cross-compiling ZeroMQ to ARM for use in a MonoTouch iPhone app configure settings

查看:23
本文介绍了将 ZeroMQ 交叉编译到 ARM 以在 MonoTouch iPhone 应用程序配置设置中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm attempting to use the ZeroMQ library in an iPhone app developed in C# using MonoTouch. I've solved almost all of the problems, but have fallen at the last hurdle. I'm using ZeroMQ 2.1.10, and the C# CLR binding/wrapper, and developing in Mac OS X 10.6.8. Here's the story so far:

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

I first attempted to use ZeroMq in a simple Mono C# Console app. I built ZeroMQ with ./configure, then make and sudo make install, which installs shared library /usr/local/lib/libzmq.dylib. The ZeroMq C# binding clrzmq.dll is a wrapper that uses the 'core' ZeroMq functionality via C Api [DllImport] calls.

测试应用程序不起作用,我发现标准 ZeroMQ ./configure 产生了 64 位输出,而 Mono 只有 32 位.然后我用

The test app didn't work, which I figured out to be that the standard ZeroMQ ./configure produces a 64-bit output, and Mono is only 32 bit. I then rebuilt ZeroMQ with

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

我的简单 C# ZeroMq 应用程序随后正常运行.

My simple C# ZeroMq app then worked correctly.

继续前进,然后我尝试从 iPhone 模拟器中的 iPhone 应用程序内部使用 ZeroMq.我发现 iPhone 只允许静态链接库(不允许动态库).这是通过将所有 C# 包装器调用更改为

Moving on, I then tried to use ZeroMq from inside an iPhone app in the iPhone simulator. I discovered that the iPhone only allows statically linked libraries (no dynamic libraries allowed). This is achieved by changing all the C# wrapper calls to

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

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

and including libzmq.a directly in the MonoTouch project, and setting extra mtouch arguments

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

确保 iPhone 应用程序中包含 ZeroMQ 库.

to ensure the ZeroMQ library is included in the iPhone app.

在 iPhone 模拟器中运行应用程序时,它崩溃了,我将其追溯到从 zmq_init()socketpair 的调用.我最终将其追溯到针对我的构建机器的 MacOS 头文件和库构建的 ZeroMQ 库,而不是针对 iPhone SDK.这是由

When running the app in the iPhone simulator, it crashed out, which I traced to a call made from a zmq_init() to socketpair. I finally traced this to the ZeroMQ library having been built against my build machine's MacOS headers and libraries, instead of against the iPhone SDK. This was fixed by

./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 构建的 i386 静态库.我现在只能在模拟器的 iPhone 应用程序中使用 ZeroMQ 功能.但是它在真正的 iPhone 上不起作用.

Success in the iPhone Simulator! The simulator requires i386 static libraries built to the iPhone simulator SDK. I now can use ZeroMQ functionality within an iPhone app in the Simulator ONLY. It does not work however on a real iPhone.

这是因为真正的 iPhone 需要一个为 ARM 架构构建的库,并针对真正的 iPhoneOS SDK.

This is because a real iPhone requires a library that has been built for the ARM architecture, and against the real iPhoneOS SDK.

(构建 3 个独立的库 - i386、ARM6 和 ARM7,并将所有 3 个组合成可在任何环境中使用的胖"库,这是一个附带问题.我需要能够为 ARM 构建之前我遇到了这个问题).

(There is a side-issue of building 3 separate libraries - i386, ARM6, and ARM7, and combining all 3 into 'fat' library that can be used in any environment. I need to be able to build for ARM before I get to this problem).

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

** Finally, my question!! **

最后一步是交叉编译ZeroMQ库到ARM.我一整天都在尝试为此找到正确的开关,并研究了互联网上我能找到的所有示例,但似乎没有一个有效的解决方案.

The last step is to cross-compile build the ZeroMQ library to ARM. I have been trying all day long to come up with the correct switches for this, and studied all the examples on the internet that I can find, but none seem to have a solution that works.

我最接近工作的是:

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

这会生成一个 make 编译 ZeroMq 代码的配置,但由于大量链接错误而失败,例如:

This produces a config which make compiles the ZeroMq code, but fails with lots of link errors, e.g.:

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

我尝试了许多其他配置,但它们甚至没有正确通过 ./configure.

I've tried many other configurations, but they don't even pass ./configure correctly.

谁能帮助我使用合适的 ./configure 参数列表来生成 ARM 架构静态库?这就是让 ZeroMQ 在真正的 iPhone 上工作所需的全部内容.

Can anyone help me with a suitable ./configure parameter list to produce an ARM architecture static library? This is all I need to get ZeroMQ working on a real iPhone.

非常感谢所有帮助!

推荐答案

只是想我会分享我最终找到了答案 - 诀窍是添加 CPP="cpp" CXXCPP="cpp"./configure 语句,给出:

Just thought I'd share that I found the answer in the end - the trick was to add CPP="cpp" CXXCPP="cpp" to the ./configure statement, giving:

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

我使用这个配置成功地为 ARM 构建了 ZeroMQ,就像我第一次 Buzzed 的新 iPhone 应用程序中使用的那样(可在 http://itunes.apple.com/gb/app/i-buzzed-first!/id490622820?mt=8 )

I used this configuration to successfully build ZeroMQ for ARM, as used in my new iPhone app I Buzzed First (available at http://itunes.apple.com/gb/app/i-buzzed-first!/id490622820?mt=8 )

这篇关于将 ZeroMQ 交叉编译到 ARM 以在 MonoTouch iPhone 应用程序配置设置中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆