The most up-to-date method to compile for iOS is from a contributor here: https://github.com/drewcrawford/libzmq-ios
He supplies some unofficial prebuilt binaries.
Other methods
A previous guide to do this seems to be written by a recent editor of this page and can be found here: http://paolodenti.blog.com/2012/07/24/zeromq-ios/
And, a corresponding github repository to be found here: https://github.com/PLG/ZeroMQ-Framework
First off - giving credit, where credit is due. Most of the material represented here is found on this stack overflow post: Cross-compiling ZeroMQ to ARM for use in a MonoTouch iPhone app configure settings.
Cross-compiling for ARM
Grab yourself a freshly baked, stable, ZeroMQ source from download page, unzip it, open terminal and create a zsh script with following contents:
You made need to update some of the paths in the script. For instance this script has an unusual directory structure (it is not the default for Xcode 5.3 on OS X Mavericks. SDK Root for example should be taken from the "xcode-select print-path" command and is normally /Applications/Xcode.app/Contents/Developer and some commands like /usr/bin/ar should be prefixed with the SDK location and of the compiler names don't seem to be present on standard Xcode builds like "/usr/bin/arm-apple-darwin10-llvm-g++-4.2"
#!/usr/bin/env zsh
make clean &>>|/dev/null
BUILD_DIR=`pwd`/build
if [[ -d $BUILD_DIR ]]; then
rm -fr $BUILD_DIR
fi
mkdir -p $BUILD_DIR
ZMQ_BUILD_LOG_FILE=$BUILD_DIR/build.log
echo "-- Configuring with prefix $BUILD_DIR"
SDK_ROOT="/Developer/Platforms/iPhoneOS.platform/Developer"
export CPP="cpp"
export CXXCPP="cpp"
export CXX="${SDK_ROOT}/usr/bin/arm-apple-darwin10-llvm-g++-4.2"
export CXXFLAGS="-O -isysroot $SDK_ROOT/SDKs/iPhoneOS5.0.sdk"
export CC="${SDK_ROOT}/usr/bin/arm-apple-darwin10-llvm-gcc-4.2"
export CFLAGS="-O -isysroot $SDK_ROOT/SDKs/iPhoneOS5.0.sdk"
export AR=$SDK_ROOT"/usr/bin/ar"
export AS=$SDK_ROOT"/usr/bin/as"
export LD=$SDK_ROOT"/usr/bin/ld"
export LDFLAGS="-lstdc++ -isysroot $SDK_ROOT/SDKs/iPhoneOS5.0.sdk"
export LIBTOOL=$SDK_ROOT"/usr/bin/libtool"
export STRIP=$SDK_ROOT"/usr/bin/strip"
export RANLIB=$SDK_ROOT"/usr/bin/ranlib"
./configure --disable-dependency-tracking --enable-static --disable-shared --host=arm-apple-darwin10 --prefix=$BUILD_DIR &>>| $ZMQ_BUILD_LOG_FILE
echo "-- Building"
make &>>| $ZMQ_BUILD_LOG_FILE
echo "-- Installing to $BUILD_DIR"
make install &>>| $ZMQ_BUILD_LOG_FILE
echo "-- Cleaning up"
make clean &>>| /dev/null
echo "-- Copying headers"
mkdir $BUILD_DIR/usr && cp -R include $BUILD_DIR/usr
Place the script into ZeroMQ directory, run the script and once it’s completed - you should have libzmq.a static library file as well as usr directory with all include headers in build subdirectory ready for use in your own iOS application. If not, the ./build/build.log file should contain all output from configure, make and make install commands to help you out while debugging the issue.
Linking with iOS project
To make ZeroMQ library actually work with your iOS project you have to add a few settings to the project. First and foremost - Framework search path. Create a Frameworks directory in your projects root directory (represented by $(SRCROOT) variable) drop the folder with libzmq.a and include headers into that directory. Then add $(SRCROOT)/Frameworks/{name_of_libzmq_folder} as a location where project should search for frameworks.
Next up - Header Search Path. Add the very same setting value to Header Search Path and don’t forget to tick the checkbox marking the path for recursive search.
And finally - add linker flag for standard C++ library. Find the Other Linker Flags setting and add -lstdc++ there. Otherwise, when linking, you’ll get loads of errors noting about unknown identifiers or symbols.
Caveats
The built library, according to Stack Overflow post’s author, should be working for iOS4 and iOS5. If you paid attention to the post - with a minor tweak you can have it working for iOS3 too.
Also - while linking it with iOS project you'll get lots of warnings about CPU_SUBTYPE_ARM_ALL constant being deprecated. I was unsuccessful in finding fix for this warning, so in my iOS debug build I silenced it with -w option for linker (Other linker flags option in Project settings). If anyone by any chance will happen to know the solution for this (probably some linker flag) please don’t hesitate and update the build script with this article.
XCode 4.3.3
This is what i did in order to compile with Xcode 4.3.3 and Clang and Xcode installed under /Applications
BUILD_DIR=`pwd`/build
if [[ -d ${BUILD_DIR} ]]; then
rm -fr ${BUILD_DIR}
fi
mkdir -p ${BUILD_DIR}
SDK_ROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer"
export CPP="cpp"
export CXXCPP="cpp"
export CXX="/usr/bin/clang"
export CC="/usr/bin/clang"
export AR="/usr/bin/ar"
export AS="/usr/bin/as"
export LD="/usr/bin/ld"
export LDFLAGS="-lstdc++"
export LIBTOOL="/usr/bin/libtool"
export STRIP="/usr/bin/strip"
export RANLIB="/usr/bin/ranlib"
./configure --disable-dependency-tracking --enable-static --disable-shared --host=arm-apple-darwin --prefix=${BUILD_DIR}
make
make install
make clean
mkdir ${BUILD_DIR}/usr && cp -R include ${BUILD_DIR}/usr
Don't try to compile the library and a project with different compilers.
ZMQ library and a project must be built by the same compiler (Apple LLVM or LLVM GCC).
If the library and a project are built by different compilers then many linker's errors will be.