Been working on this for hours now so any insight would be greatly appreciated.
I'm trying to compile libssh2 for the iPhone Simulator on OS X (I already have it compiled successfully for the device).
I'm using the following environment variables and commands:
export DEVROOT=/Developer/Platforms/iPhoneSimulator.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneSimulator3.0.sdk
export CC=$DEVROOT/usr/bin/gcc-4.2
export LD=$DEVROOT/usr/bin/ld
export CPP=$DEVROOT/usr/bin/cpp-4.2
export CXX=$DEVROOT/usr/bin/g++-4.2
export AR=$DEVROOT/usr/bin/ar
export AS=$DEVROOT/usr/bin/as
export NM=$DEVROOT/usr/bin/nm
export CXXCPP=$DEVROOT/usr/bin/cpp-4.2
export RANLIB=$DEVROOT/usr/bin/ranlib
export LDFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot $SDKROOT -L/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os/lib"
export CFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot $SDKROOT -I/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os/include"
export CXXFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot $SDKROOT -I/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os/include/"
export CFLAGS=-m32
export CPPFLAGS=-m32
cd /Users/<USERNAME>/Desktop/Dev/src/gnupg-1.4.10
sudo ./configure --host=i386-apple-darwin --prefix=/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os
sudo make
sudo make install
cd /Users/<USERNAME>/Desktop/Dev/src/libgpg-error-1.7
sudo ./configure --host=i386-apple-darwin --prefix=/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os --enable-shared=no
sudo make
sudo make install
cd /Users/<USERNAME>/Desktop/Dev/src/libgcrypt-1.4.5
sudo ./configure --host=i386-apple-darwin --prefix=/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os --enable-shared=no --with-gpg-error-prefix=/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os --disable-asm
sudo make
sudo make install
sudo ./configure --host=i386-apple-darwin --prefix=/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os --with-libgcrypt-prefix=/Users/<USERNAME>/Desktop/Dev/src/libgcrypt-1.4.5
cd /Users/<USERNAME>/Desktop/Dev/src/libssh2-1.2.7
sudo make
sudo make install
The dylib that is produced shows as x86_64 and when trying to use the static library .a file in the iPhone app is says libssh2.a, file was built for unsupported file format which is not the architecture being linked (i386).
libgcrypt and the other required libraries have all compiled with no issue.
Thanks in advance!
I ran into pretty much this same problem. I was compiling libssh2, but I was using openssl with it. To force configure to compile in 32 bit mode you will need to set the CFLAGS and CPPFLAGS. Enter these commands in the terminal before you run configure:
Before running ./configure in the Terminal, you need to set the CFLAGS and CPPFLAGS.
export CFLAGS=-m32
export CPPFLAGS=-m32
To build libssh2 with openssl the way I did it first download the latest openssl and libssh2 source files from their respective sites. Go to the directory you downloaded and unzipped openssl to. I actually did the above commands after I built the openssl binaries and it didn't seem to matter. They were required before building libssh2 though.
./configure --prefix=/TARGET_DIRECTORY
make
make install
After that switch over to the folder where you downloaded and unzipped libssh2. Configure and build it with the following commands:
./configure --with-openssl --with-libssl-prefix=/OPENSSL_TARGET_DIRECTORY --prefix=/LIBSSH2_TARGET_DIRECTORY
make
make install
You can find the *.a files to import into the Xcode project in the target directorys' "lib" folders.
As I'm sure you already know, this is only for the iPhone simulator. You'll need to build for the arm architecture to use this library on a device.
The following environment worked for me to build libssh2 and libssl for iPhone Simulator.