Using libraraies - iphone

I have a Library built in Macosx ibopencore-amrnb.a. Can I use it with my Iphone app as library? If yes How ? If not How Do i get the library working with Iphone app?
Thanks,
Sowri

Mac osX is an X86 platform the iphone uses an ARM processor so at the very least it needs to be recompiled.The architectures are very different ,though, so things like endeaness(?) and word size must be taken into consideration.

Step 1) Build the static libraries.
I've built third-party libraries, statically, for the iPhone. After a bit of trial-and-error, here's what I found to be a good starting point:
Cross-Compile for iPhoneOS:
./configure --prefix=/path/to/project/external/iphoneos/ --host="arm-apple-darwin9" --target=arm-apple-darwin9 --enable-static --disable-shared CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.0.1 CFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk" CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp
make
make install
Cross-Compile for iPhoneSimulator:
./configure --prefix=/path/to/project/external/iphonesimulator --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.0 CFLAGS="-arch i686 -pipe -mdynamic-no-pic -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -mmacosx-version-min=10.5 -I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/include/ -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk" CPP=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar LDFLAGS="-arch i686 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk -Wl,-dead_strip -mmacosx-version-min=10.5"
make
make install
However, it's really just a starting point. It'll probably only work for projects with flexible Makefiles. If the above doesn't work, I've had to:
turn on project-specific ./configure flags
modify the configure script
modify the generated Makefile
modify autoconfigure scripts
You can also turn on optimization flags for the iPhoneOS version (after you've got it working first).
Step 2) Add the libraries to your project's search path.
In your projects Info settings, set these Build options:
Header Search Paths: "$(SRCROOT)/external/$(PLATFORM_NAME)/include"
Library Search Paths: "$(SRCROOT)/external/$(PLATFORM_NAME)/lib"
Other Linker Flags: [Add the flags for your static libs]
Afterwards, you should be able to include the third-party libraries in your project.

Related

Compiling Freetype 2.6.5 Xcode for IOS

Alright guys, I posted a similar question and took it down because it wasn't specific enough so here I go. From the zip file of Freetype 2.6.5 I have not been able to create an Xcode project that will compile the library for iOS use, only for i386_64.
I tried the commands here but I don't get past the first commands the and I am getting this
FreeType build system -- automatic system detection
The following settings are used:
platform unix compiler cc
configuration directory ./builds/unix configuration rules
./builds/unix/unix.mk
If this does not correspond to your system or settings please remove
the file `config.mk' from this directory then read the INSTALL file
for help.
Otherwise, simply type
/Applications/Xcode.app/Contents/Developer/usr/bin/make' again to
build the library, or
/Applications/Xcode.app/Contents/Developer/usr/bin/make refdoc' to
build the API reference (this needs python >= 2.6).
cd builds/unix; \
./configure 'CFLAGS=-arch i386' /bin/sh: ./configure: No such file or directory make: *** [setup] Error 127
I also followed the instructions inside the cmakelists.txt that it comes inside the project but still nothing, I still get an xcode project for osx and not for IOS which is giving me a plethora of linking errors. Here is the instructions for your reference.
For an iOS static library, use
#
cmake -D IOS_PLATFORM=OS -G Xcode
#
or
#
cmake -D IOS_PLATFORM=SIMULATOR -G Xcode
I am not sure what else to do. Any help?
Here's an outline of the basic build process to compile the FreeType libaries for iOS:
Download the latest FreeType source code
Extract the archive and cd into the unarchived directory
Setup toolchain and export variables for the architectures desired (arm64, arm7, i386, x86_64)
Compile the source code and build the libraries
For example, the build commands for arm64 might look something like this:
$ export CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
$ iphoneos="7.0" # target version of iOS
$ ARCH="arm64" # architecture (arm64, arm7, i386, x86_64)
$ export CFLAGS="-arch ${ARCH} -pipe -mdynamic-no-pic -Wno-trigraphs -fpascal-strings \
-O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden \
-miphoneos-version-min=$iphoneos -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2 \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
$ export AR="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar"
$ export LDFLAGS="-arch ${ARCH} -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk \
-miphoneos-version-min=7.0"
$ ./configure --host="aarch64-apple-darwin" --enable-static=yes --enable-shared=no
$ make
$ clean
It's a bit of work to construct the commands for each arch, but
fortunately there's a build
script
— which automatically downloads, extracts, and builds the latest FreeType (2.6.5 currently).
To run the script just use the following command in Terminal:
./build_freetype.sh
The resulting iOS libraries can be found in ~/Desktop/FreeType_iOS_Release when it completes.

How to use jpeglib in xCode

I'm developing an iPhone application and I'm kind of new to everything. I'm working on Mountain Lion OS X 10.8 and using xCode v4.5. I need JPEG handling capabilities in my project and I want to use the libjpeg (http://www.ijg.org/) library. I have tried a few different approaches, but being a bit naive, I'm not really sure how to begin. After downloading packages I've made usual ./configure; make and make install. Right now I have (jconfig.h, jerror.h, jmorecfg.h, jpeglib.h) under (/usr/local/include) and (libjpeg.a, libjpeg.la) under (/usr/local/lib) but I have no idea how to link/use this in my xCode project.
Can anyone link me to a tutorial or give me a push in the right direction?
If anyone successfully installed and used jpeg library please help..
This is a bit of a pain, because you will need to compile LibJPEG for two architectures: ARM, for iOS, and x86, for the simulator.
Your best bet is to use NSImage or CGImage. There already is a JPEG library on iOS, supplied with the system, so you don't need to use LibJPEG.
An alternative is to put the LibJPEG sources directly into your project (including the *.c files). This way, they will be built correctly for different architectures (simulation and deployment).
You could also just build for ARM, and then forget about running the simulator.
Or you could build LibJPEG as a fat binary by compiling it twice and combining the resulting library (libjpeg.a) from each compilation with libtool.
libtool -static path/to/arm/libjpeg.a path/to/x86/libjpeg.a -o libjpeg.a
You can see why the recommendation is to use NSImage or CGImage. Better to use a library that is already installed rather than try to build and install a new one.
How to make a fat static library
Since it sounds like you want to do things the hard way, here is an example of how to build a fat static library for i386 and ppc architectures. This was done on a PowerPC OS X box, you will have to adjust if you want to compile for ARM and i386.
Note that you have to specify --host and --build for cross-compiling. The values below are correct for my computer, but I am certain that they are wrong for your computer.
$ cd jpeg-8d
$ mkdir build-ppc build-i386
$ cd build-ppc
$ ../configure CFLAGS='-arch ppc -O2 -g' LDFLAGS='-arch ppc' \
--enable-static --disable-shared
$ make -j2
$ cd ../build-i386
$ ../configure CFLAGS='-arch i386 -O2 -g' LDFLAGS='-arch i386' \
--enable-static --disable-shared \
--build=powerpc-apple-darwin9.8.0 --host=i386-apple-darwin9.8.0
$ make -j2
$ cd ..
$ file build-ppc/.libs/libjpeg.a
build-ppc/.libs/libjpeg.a: current ar archive random library
$ file build-i386/.libs/libjpeg.a
build-i386/.libs/libjpeg.a: current ar archive random library
$ libtool -static build-*/.libs/libjpeg.a -o libjpeg.a
$ file libjpeg.a
libjpeg.a: Mach-O universal binary with 2 architectures
libjpeg.a (for architecture i386): current ar archive random library
libjpeg.a (for architecture ppc): current ar archive random library

When compiling a static libssh2 library as i386 it always returns an x86_64 library

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:
export CFLAGS=-m32
export CPPFLAGS=-m32
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.
export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneOS4.2.sdk
export CC=$DEVROOT/usr/bin/gcc
export LD=$DEVROOT/usr/bin/ld
export CPP=$DEVROOT/usr/bin/cpp
export CXX=$DEVROOT/usr/bin/g++
export AR=$DEVROOT/usr/bin/ar
export AS=$DEVROOT/usr/bin/as
export NM=$DEVROOT/usr/bin/nm
export CXXCPP=$DEVROOT/usr/bin/cpp
export RANLIB=$DEVROOT/usr/bin/ranlib
export LDFLAGS="-arch i386 -L/Users/user/project/third_party/lib"
export CFLAGS="-arch i386 -I/Users/user/project/third_party/include"
export CXXFLAGS="-arch i386 -I/Users/user/project/third_party"

Force libpq to compile with 10.5

I need to compile libpq with 10.5 for using later in the simulator.
I can use the libpq in the device without problems.
I'm forcing with this:
make clean && ./configure CFLAGS="-arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk" && make -C src/interfaces/libpq
but I'm getting the error:
ld: library not found for -
This library doesn't exist in the MacOSX10.5 folder, well, it doesn't exist in my entire hard drive.
thanks,
m.
OS X 10.6.2
XCode 3.2.1 64 bits
ok, now it works:
-mmacosx-version-min=10.5
make clean && ./configure CFLAGS="-arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5" && make -C src/interfaces/libpq
Here is a link to a question I asked while back that might be nice to have as part of this question.
Connect iPhone App to PostgreSQL Using Libpq
Also a link that had the info I used to figure out how to do it.
http://cocoawithlove.com/2009/09/building-for-earlier-os-versions-in.html

Building from the command line to produce a binary for Mac OS 10.5 (and 10.6)

I am referring to the following source: http://clpbar.sourceforge.net
Build process is the standard: ./configure followed by make
If I build on 10.5 I get a binary whose file contains: Mach-O executable i386
If I build on 10.6 I get a binary whose file contains: Mach-O 64-bit executable x86_64
How can I build from the command line on 10.6 and produce an executable of the type Mach-O executable i386, or even better a Universal binary containing executables of both types.
Please test any suggested solutions.
Thanks,
matt
By default, the version of GCC distributed with OS X 10.6 builds 64-bit binaries. The version of GCC distributed with 10.5 builds 32-bit binaries by default.
Before running ./configure, set a few environment variables. If you want it to be an Intel universal binary with i386 and x86_64 code, set the following variables (assuming you're using bash):
export CFLAGS="-arch i386 -arch x86_64"
export CXXFLAGS=$CFLAGS
export LDFLAGS=$CFLAGS
This will tell the configure script to pass these compiler and linker options, and thus build a binary with both the i386 and x86_64 architectures.
Or, if you want it to only build as an i386 binary:
export CFLAGS="-arch i386"
export CXXFLAGS=$CFLAGS
export LDFLAGS=$CFLAGS
From the Apple dev forums:
./configure CC="gcc -arch i386" CXX="g++ -arch i386"
Which works perfectly.
Use a -arch flag for each target. So, e.g.
gcc -arch i386 -arch x86_64 ...
would build a fat binary with both. I believe by default gcc builds to the target architecture, which is x86_64 with OSX 10.6.