computer, travel, movies, music, cuisine and more
ImageMagick on iPhone (with jpeg + png)
>> PLEASE READ THE UPDATE <<
I’m working on some iPhone applications, which need some image filtering. For now, I won’t say more! Stay tuned for the news when it comes out!
Long story short, I soon found the need (ant the challenge was a good one) to get ImageMagick static libraries so that I can use it on the iPhone. Not only that, but with jpeg and png support. That’s what I need.
After a fast search through the net, I couldn’t find a single _GOOD_ post on how to do that. Just some bits and bytes – Nothing complete.
I soon set on a mission to get ImageMagick to work on the iPhone, as a library. And here’s the result of my quest (around 1 day of search, trials and errors, and at last some light!)
Setting
I’m running MacOSX 10.5.7, with the latest MacPorts installed. If you don’t, get it! I have many ports installed, the ones I “think” are important are:
- jpeg
- libpng
Also, I’m testing everything with the latest beta of the iPhoneOS 3.0 – It should be working also for 2.2.1 and the final 3.0 when it comes out.
The Script
I now provide you with a shell script that should do the whole trick of creating the static libraries needed in Xcode for iPhone development.
Just download it, give it run permission (chmod +x ./compile_im.sh), and launch it. It will ask for your password because it needs to copy a file that is not owned by you, the user.
Before complaining that it’s not working, open it, and look at the required directory structure for it to work.
In particular you will need:
- a Desktop folder named cross_compile
- ImageMagick source: ImageMagick
- jpeg source: jpeg
- libpng source: libpng
- Untar ImageMagick source and place it into ~/Desktop/cross_compile/i_m
- Untar/Unzip jpeg/libpng source and place it into: ~/Desktop/cross_compile/i_m/IMDelegates/jpeg-6b and ~/Desktop/cross_compile/i_m/IMDelegates/libpng-1.2.37
– to which I’ve added the MacPorts patches
Now you can run the script :)
Result
The result will be stored under: ~/Desktop/tmp_target. In particular you can find all the header files needed while developing your application under: ~/Desktop/tmp_target/im_libs/includes (divided by library). While all the static libraries are inside ~/Desktop/tmp_target/im_libs/:
- libjpeg.a
- libpng.a
- libMagickCore.a
- libMagickWand.a
Please note that the script joins both the i386 and the arm build inside one single .a static library to ease up developing (for testing both on the Simulator and on the device itself. When finishing up the application you may want to put only the arm library to make the overall application lighter.
XCode configuration
Step 1
To work with your libraries you need to put some easy adjustments to your Project in XCode. I’ve found that the best thing to do, especially in a shared environment with multiple developers, to just put everything inside the XCode project. To do so do:
- Project->Add To Project->Select all the .a libraries->Click ‘ADD’
- Project->Add To Project->Select the folders inside the ~/Desktop/tmp_target/im_libs/include->Click ‘ADD’
Step 2
Click on Project->Edit Project Settings and edit (in the Build:
- Other Linker Flags: -lMagickCore -lMagickWand -lz -lbz2 -ljpeg -lpng
- Header Search Paths: $(SRCROOT) – make it Recursive
- Library Search Paths: $(SRCROOT) – make it Recursive
- On the lower left click on the small-wheel and select: Add User-Defined Setting
- Key: OTHER_CFLAGS
- Value: -Dmacinsoth=1
This should be enough to make you start.
For the Lazy
If you’re lazy, don’t manage or for whatever other reason you can just download the whole compiled package
Last note
In case the script doesn’t work, you have questions/suggestions/support please don’t hesitate to contact me, and in case you need help with the script please send me the FULL output in a file.
./compile_im.sh > file_to_send.txt
| Print article | This entry was posted by Cloud on June 9, 2009 at 11:37 pm, and is filed under Code, tips & howtos. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 2 weeks ago
Hi, Cloud!
At the first, thanks for your post. It’s very useful.
But I have a problem with use this. Could you please help me to resolve this issue?
If I use your compiled library my project works perfectly.
But when I build a library myself and insert it into my project, the function
MagickReadImageBlob(i_wand, [dataObject bytes], [dataObject length])
returns false always (dataObject is a NSDate that contains jpeg image).
The compilation is finished successfully, without any errors. BUT my libMagickCore has a size 9,8 MB versus your 10,0 MB.
Do you have any thoughts about this?
Thank you.
P.S. I have compiled it on Mac OS 10.5.8
about 2 weeks ago
Hi,
I do not know what that problem could be, but apparently something didn’t compile properly. Two things to do:
1) Try to have dataObject to be something with a png rather than a jpeg and see if it works, this would mean that jpeg didn’t compile correctly
2) when compiling output everything to a file and send me the file, so I can have a look at it, to do this:
./compile_im.sh > ~/Desktop/compilation_output
about 2 weeks ago
I have gotten the same error with PNG.
And I have a log, but I can’t find your email, where can I send log?
about 3 weeks ago
Hi,
Thanks for your post :)
I compiled well and Imagemagick worked well.
After I update my leopard to snow leopard,
and update my xcode to 3.2
when I compile my project for simulator
it gives me library error
———————
“_GOMP_critical_name_start”, referenced from:
“_GOMP_parallel_loop_dynamic_start”, referenced from:
“_GOMP_loop_dynamic_start”, referenced from:
and similar errors…
———————
Do you know why these happens?
It works on device well! :O
Is there some library I missed?
or is there some check point when I migrate from 3.1 to 3.2 xcode?
please help me, thank you
about 3 weeks ago
Hi, did you have a look at the new script that I have posted? Please first have a look at it and let me know if you still get that error (http://www.cloudgoessocial.net/2010/02/10/imagemagick-for-iphone-via-snowleopard/)
~C
about 1 month ago
hi everyone,
I want to use imageMagick for taking pdf cover thumbnails?
Any Suggestion would be greatly appreciated.
Thanks.
about 3 months ago
Hi Everyone
Has anyone been able to build it with Snow Leopard?
I am trying something similar using Tesseract. I can build the library on the ARM architecture, include it in my project but impossible to get it to work on the Simulator. I get the error “ld: warning: in /Developer/photoStrip/lib/iPhone/libtesseract_full.a, file is not of required architecture” when I build the App. I also tried with the setup (x86_64) Christophe Verdier recommended.
My Setup is Snow Leopard 10.6.2, SDK 3.1, XCode 3.2.
Any help would be greatly appreciated
Thanks
about 2 weeks ago
Please look at http://www.cloudgoessocial.net/2010/02/10/imagemagick-for-iphone-via-snowleopard/
for instructions on how to compile it under SnowLeopard.
about 5 months ago
update: the modified script for snow…
worked for me at least :)
# Author: Claudio Marforio
# e-mail: marforio@gmail.com
# date: 9.06.2009
# Script to make static libraries (jpeg + png) and ImageMagick
# the libraries will be conbined into i386+arm.a static libraries
# to be used inside an XCODE project for iPhone development
# The directory structure has to be:
# ~/Desktop/cross_compile/i_m/ <- ImageMagick top directory
# |-IMDelegataes/ <- Some delegates, in particular jpeg + png
# |-jpeg-6b/ <- Patched jpeg6b
# |-libpng-1.2.37 <- png lib – no need to patch it
# |-tiff-3.8.2 <- tiff lib – no need to patch it
# |-… <- we don't care what's here! :)
# If you don't have this Directory structure you can either create it or try change around the script
#!/bin/bash
# Set this to the top directory of ImageMagick source:
IM_DIR=$(pwd)/cross_compile/i_m
JPEG_DIR=$IM_DIR/IMDelegates/jpeg-6b
PNG_DIR=$IM_DIR/IMDelegates/libpng-1.2.40
TIFF_DIR=$IM_DIR/IMDelegates/tiff-3.9.1
ARCH_SIM="i386"
GCC_VERSION="4.0.1"
# Set this to where you want the libraries to be placed (if dir is not present it will be created):
TARGET_LIB_DIR=$(pwd)/tmp_target
LIB_DIR=$TARGET_LIB_DIR/im_libs
JPEG_LIB_DIR=$TARGET_LIB_DIR/libjpeg
PNG_LIB_DIR=$TARGET_LIB_DIR/libpng
TIFF_LIB_DIR=$TARGET_LIB_DIR/libtiff
IM_LIB_DIR=$TARGET_LIB_DIR/imagemagick
# Set the build directories
mkdir -p $TARGET_LIB_DIR
mkdir -p $LIB_DIR/include/jpeg
mkdir -p $LIB_DIR/include/magick
mkdir -p $LIB_DIR/include/png
mkdir -p $LIB_DIR/include/tiff
mkdir -p $LIB_DIR/include/wand
mkdir -p $LIB_DIR/jpeg_arm_dylib
mkdir -p $LIB_DIR/png_arm_dylib
mkdir -p $LIB_DIR/tiff_arm_dylib
mkdir -p $JPEG_LIB_DIR/lib #we don't need bin/ and share/
mkdir -p $JPEG_LIB_DIR/include
mkdir -p $PNG_LIB_DIR #libpng manages to create subdirectories by itself with make install
mkdir -p $TIFF_LIB_DIR #libtiff manages to create subdirectories by itself with make install
# General folders where you have the iPhone compiler + tools
export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
# Change this to match for which version of the SDK you want to compile – you can change the number for the version
export SDKROOT=$DEVROOT/SDKs/iPhoneOS3.1.sdk
############ HACK #################################
# ImageMagick requires this header, that doesn't exist for the iPhone
# Just copying it make things compile/work (more testing needed)
#sudo cp /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/usr/include/crt_externs.h \
# $SDKROOT/usr/include/crt_externs.h
############ END – HACK #############################
function png()
{
#######################################################
############ PNG ###########################
#######################################################
cd $PNG_DIR
LIBPATH_png=libpng12.a
#######################################################
############ ARM ###########################
#######################################################
U_CC=$CC
U_CFLAGS=$CFLAGS
U_LD=$LD
U_LDFLAGS=$LDFLAGS
U_CPP=$CPP
U_CPPFLAGS=$CPPFLAGS
export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/$GCC_VERSION/include/ -I$SDKROOT/usr/include/"
export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -I$SDKROOT/usr/include -L$SDKROOT/usr/lib/ -O3"
export CPP="/usr/bin/cpp $CPPFLAGS"
export LDFLAGS="-L$SDKROOT/usr/lib/"
./configure prefix=$PNG_LIB_DIR –enable-shared –enable-static \
CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-$GCC_VERSION LD=$DEVROOT/usr/bin/ld –host=arm-apple-darwin
make
make install
# cp the static + shared library
cp $PNG_LIB_DIR/lib/$LIBPATH_png $LIB_DIR/libpng.a.arm
cp $PNG_LIB_DIR/lib/libpng12.0.dylib $LIB_DIR/png_arm_dylib/libpng.dylib
make distclean
#######################################################
############ INTEL ###########################
#######################################################
# Use default environment
export CC=$U_CC
export CFLAGS="-arch $ARCH_SIM -O3"
export LD=$U_LD
export LDFLAGS=$U_LDFLAGS
export CPP=$U_CPP
export CPPFLAGS=$U_CPPFLAGS
LIBPATH_png=libpng12.a
./configure prefix=$PNG_LIB_DIR –enable-shared –enable-static –host=i686-apple-darwin9
make
make install
# cp the static library
cp $PNG_LIB_DIR/lib/$LIBPATH_png $LIB_DIR/libpng.a.i386
# cp the include/* files
cp $PNG_LIB_DIR/include/libpng12/* $LIB_DIR/include/png/
make distclean
# combine the static libraries for i386 and arm
$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/libpng.a.arm -arch $ARCH_SIM $LIB_DIR/libpng.a.i386 -create -output $LIB_DIR/libpng.a
}
function jpeg()
{
#######################################################
############ JPEG ###########################
#######################################################
cd $JPEG_DIR
LIBPATH_jpeg=libjpeg.a
LIBNAME_jpeg=`basename $LIBPATH_jpeg`
#######################################################
############ ARM ###########################
#######################################################
U_CC=$CC
U_CFLAGS=$CFLAGS
U_LD=$LD
U_LDFLAGS=$LDFLAGS
U_CPP=$CPP
U_CPPFLAGS=$CPPFLAGS
export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/$GCC_VERSION/include/ -I$SDKROOT/usr/include/"
export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -I$SDKROOT/usr/include -L$SDKROOT/usr/lib/ -O3"
export CPP="/usr/bin/cpp $CPPFLAGS"
export LDFLAGS="-L$SDKROOT/usr/lib/"
./configure prefix=$JPEG_LIB_DIR –enable-shared –enable-static \
CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-$GCC_VERSION LD=$DEVROOT/usr/bin/ld –host=arm-apple-darwin
make
make install-lib
# cp the static + shared library
cp $JPEG_LIB_DIR/lib/$LIBPATH_jpeg $LIB_DIR/$LIBNAME_jpeg.arm
cp $JPEG_LIB_DIR/lib/libjpeg.62.0.0.dylib $LIB_DIR/jpeg_arm_dylib/libjpeg.dylib
make distclean
#######################################################
############ INTEL ###########################
#######################################################
# Use default environment
export CC=$U_CC
export CFLAGS="-arch $ARCH_SIM -O3"
export LD=$U_LD
export LDFLAGS=$U_LDFLAGS
export CPP=$U_CPP
export CPPFLAGS=$U_CPPFLAGS
./configure prefix=$JPEG_LIB_DIR –enable-shared –enable-static –host=i686-apple-darwin9
make
make install-lib
# cp the static library
cp $JPEG_LIB_DIR/lib/$LIBPATH_jpeg $LIB_DIR/$LIBNAME_jpeg.i386
# cp the include/* files
cp $JPEG_LIB_DIR/include/*.h $LIB_DIR/include/jpeg/
make distclean
# combine the static libraries for i386 and arm
$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/$LIBNAME_jpeg.arm -arch $ARCH_SIM $LIB_DIR/$LIBNAME_jpeg.i386 -create -output $LIB_DIR/$LIBNAME_jpeg
}
function tiff()
{
########################################################
############# TIFF ############################
########################################################
cd $TIFF_DIR
LIBPATH_tiff=libtiff.a
LIBNAME_tiff=`basename $LIBPATH_tiff`
if [ "$1" == "arm" ]; then
#######################################################
############ ARM ###########################
#######################################################
U_CC=$CC
U_CFLAGS=$CFLAGS
U_LD=$LD
U_LDFLAGS=$LDFLAGS
U_CPP=$CPP
U_CPPFLAGS=$CPPFLAGS
export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/$GCC_VERSION/include/ -I$SDKROOT/usr/include/"
export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -I$SDKROOT/usr/include -L$SDKROOT/usr/lib/ -O3"
export CPP="/usr/bin/cpp $CPPFLAGS"
export LDFLAGS="-L$SDKROOT/usr/lib/"
./configure prefix=$TIFF_LIB_DIR CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-$GCC_VERSION \
LD=$DEVROOT/usr/bin/ld –host=arm-apple-darwin –disable-cxx \
&& make \
&& make install
# cp the static + shared library
cp $TIFF_LIB_DIR/lib/$LIBPATH_tiff $LIB_DIR/$LIBNAME_tiff.arm
cp $TIFF_LIB_DIR/lib/libtiff.3.dylib $LIB_DIR/tiff_arm_dylib/libtiff.dylib
make distclean
elif [ "$1" == "$ARCH_SIM" ]; then
#######################################################
############ INTEL ###########################
#######################################################
# Use default environment
export CC=$U_CC
export CFLAGS="-arch $ARCH_SIM"
export LD=$U_LD
export LDFLAGS=$U_LDFLAGS
export CPP=$U_CPP
export CPPFLAGS=$U_CPPFLAGS
./configure prefix=$TIFF_LIB_DIR –host=i686-apple-darwin9 –disable-cxx \
&& make \
&& make install
# cp the static library
cp $TIFF_LIB_DIR/lib/$LIBPATH_tiff $LIB_DIR/$LIBNAME_tiff.i386
# cp the include/* files
cp $TIFF_LIB_DIR/include/*.h $LIB_DIR/include/tiff/
make distclean
# combine the static libraries for i386 and arm
$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/$LIBNAME_tiff.arm -arch $ARCH_SIM $LIB_DIR/$LIBNAME_tiff.i386 -create -output $LIB_DIR/$LIBNAME_tiff
fi
}
function im()
{
#######################################################
############ IMAGEMAGICK #######################
#######################################################
cd $IM_DIR
# static library that will be generated
LIBPATH_static=$IM_LIB_DIR/lib/libMagickCore.a
LIBNAME_static=`basename $LIBPATH_static`
LIBPATH_static2=$IM_LIB_DIR/lib/libMagickWand.a
LIBNAME_static2=`basename $LIBPATH_static2`
#######################################################
############ ARM ###########################
#######################################################
# Save relevant environment
U_CC=$CC
U_CFLAGS=$CFLAGS
U_LD=$LD
U_LDFLAGS=$LDFLAGS
U_CPP=$CPP
U_CPPFLAGS=$CPPFLAGS
export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/$GCC_VERSION/include/ -I$SDKROOT/usr/include/"
export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -I$SDKROOT/usr/include -I$LIB_DIR/include -O3"
export LDFLAGS="-L$LIB_DIR/jpeg_arm_dylib/ -L$LIB_DIR/png_arm_dylib/ -L$LIB_DIR/tiff_arm_dylib/ -L$SDKROOT/usr/lib/"
export CPP="/usr/bin/cpp $CPPFLAGS"
export CXXFLAGS="-O3 -Wall -W -D_THREAD_SAFE"
# configure to have the static libraries and make
./configure prefix=$IM_LIB_DIR CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-$GCC_VERSION LD=$DEVROOT/usr/bin/ld –host=arm-apple-darwin \
–disable-largefile –with-quantum-depth=8 –without-magick-plus-plus –without-perl –without-x –without-freetype \
–disable-shared
# compile ImageMagick
make
make install
# copy the CORE + WAND libraries – ARM version
cp $LIBPATH_static $LIB_DIR/$LIBNAME_static.arm
cp $LIBPATH_static2 $LIB_DIR/$LIBNAME_static2.arm
# clean the ImageMagick build
make distclean
#######################################################
############ INTEL ###########################
#######################################################
# Use default environment
export CC=$U_CC
export CFLAGS="-arch $ARCH_SIM -O3"
export LD=$U_LD
export LDFLAGS=$U_LDFLAGS
export CPP=$U_CPP
export CPPFLAGS=$U_CPPFLAGS
# configure with standard parameters
./configure prefix=$IM_LIB_DIR –host=i686-apple-darwin9 –without-magick-plus-plus –without-perl –without-x –without-freetype –disable-shared
# compile ImageMagick
make
make install
# copy the CORE + WAND libraries – INTEL version
cp $LIBPATH_static $LIB_DIR/$LIBNAME_static.i386
cp $LIBPATH_static2 $LIB_DIR/$LIBNAME_static2.i386
# copy the wand/ + core/ headers
cp $IM_LIB_DIR/include/ImageMagick/magick/* $LIB_DIR/include/magick/
cp $IM_LIB_DIR/include/ImageMagick/wand/* $LIB_DIR/include/wand/
# clean the ImageMagick build
make distclean
# combine the two generated libraries to be used both in the simulator and in the device
$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/$LIBNAME_static.arm -arch $ARCH_SIM $LIB_DIR/$LIBNAME_static.i386 -create -output $LIB_DIR/$LIBNAME_static
$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/$LIBNAME_static2.arm -arch $ARCH_SIM $LIB_DIR/$LIBNAME_static2.i386 -create -output $LIB_DIR/$LIBNAME_static2
}
png
jpeg
tiff "arm"
tiff "$ARCH_SIM"
im
about 5 months ago
I’m getting :
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/lipo: specifed architecture type (arm) for file (/Users/oliver/Desktop/tmp_target/im_libs/libMagickCore.a.arm) does not match it’s cputype (7) and cpusubtype (3) (should be cputype (12) and cpusubtype (0))
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/lipo: specifed architecture type (arm) for file (/Users/oliver/Desktop/tmp_target/im_libs/libMagickWand.a.arm) does not match it’s cputype (7) and cpusubtype (3) (should be cputype (12) and cpusubtype (0))
As a result my libMagickWand.a and libMagickCore.a are not created. How do I fix it ?
about 5 months ago
on snow change the last 2 lines of the script by this :
$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/$LIBNAME_static.arm -arch x86_64 $LIB_DIR/$LIBNAME_static.i386 -create -output $LIB_DIR/$LIBNAME_static
$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/$LIBNAME_static2.arm -arch x86_64 $LIB_DIR/$LIBNAME_static2.i386 -create -output $LIB_DIR/$LIBNAME_static2
about 5 months ago
Thank you very much for this fix, I will update the fixed scrip ASAP, I’m very busy with other projects now…
about 5 months ago
my mistake, few additional modification have to be done :
the script below worked for me on snow
# Author: Claudio Marforio
# e-mail: marforio@gmail.com
# date: 9.06.2009
# Script to make static libraries (jpeg + png) and ImageMagick
# the libraries will be conbined into i386+arm.a static libraries
# to be used inside an XCODE project for iPhone development
# The directory structure has to be:
# ~/Desktop/cross_compile/i_m/ <- ImageMagick top directory
# |-IMDelegataes/ <- Some delegates, in particular jpeg + png
# |-jpeg-6b/ <- Patched jpeg6b
# |-libpng-1.2.37 <- png lib – no need to patch it
# |-tiff-3.8.2 <- tiff lib – no need to patch it
# |-… <- we don't care what's here! :)
# If you don't have this Directory structure you can either create it or try change around the script
#!/bin/bash
# Set this to the top directory of ImageMagick source:
IM_DIR=$(pwd)/cross_compile/i_m
JPEG_DIR=$IM_DIR/IMDelegates/jpeg-6b
PNG_DIR=$IM_DIR/IMDelegates/libpng-1.2.40
TIFF_DIR=$IM_DIR/IMDelegates/tiff-3.9.1
ARCH_SIM="i386"
GCC_VERSION="4.0.1"
# Set this to where you want the libraries to be placed (if dir is not present it will be created):
TARGET_LIB_DIR=$(pwd)/tmp_target
LIB_DIR=$TARGET_LIB_DIR/im_libs
JPEG_LIB_DIR=$TARGET_LIB_DIR/libjpeg
PNG_LIB_DIR=$TARGET_LIB_DIR/libpng
TIFF_LIB_DIR=$TARGET_LIB_DIR/libtiff
IM_LIB_DIR=$TARGET_LIB_DIR/imagemagick
# Set the build directories
mkdir -p $TARGET_LIB_DIR
mkdir -p $LIB_DIR/include/jpeg
mkdir -p $LIB_DIR/include/magick
mkdir -p $LIB_DIR/include/png
mkdir -p $LIB_DIR/include/tiff
mkdir -p $LIB_DIR/include/wand
mkdir -p $LIB_DIR/jpeg_arm_dylib
mkdir -p $LIB_DIR/png_arm_dylib
mkdir -p $LIB_DIR/tiff_arm_dylib
mkdir -p $JPEG_LIB_DIR/lib #we don't need bin/ and share/
mkdir -p $JPEG_LIB_DIR/include
mkdir -p $PNG_LIB_DIR #libpng manages to create subdirectories by itself with make install
mkdir -p $TIFF_LIB_DIR #libtiff manages to create subdirectories by itself with make install
# General folders where you have the iPhone compiler + tools
export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
# Change this to match for which version of the SDK you want to compile – you can change the number for the version
export SDKROOT=$DEVROOT/SDKs/iPhoneOS3.1.sdk
############ HACK #################################
# ImageMagick requires this header, that doesn't exist for the iPhone
# Just copying it make things compile/work (more testing needed)
#sudo cp /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/usr/include/crt_externs.h \
# $SDKROOT/usr/include/crt_externs.h
############ END – HACK #############################
function png()
{
#######################################################
############ PNG ###########################
#######################################################
cd $PNG_DIR
LIBPATH_png=libpng12.a
#######################################################
############ ARM ###########################
#######################################################
U_CC=$CC
U_CFLAGS=$CFLAGS
U_LD=$LD
U_LDFLAGS=$LDFLAGS
U_CPP=$CPP
U_CPPFLAGS=$CPPFLAGS
export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/$GCC_VERSION/include/ -I$SDKROOT/usr/include/"
export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -I$SDKROOT/usr/include -L$SDKROOT/usr/lib/ -O3"
export CPP="/usr/bin/cpp $CPPFLAGS"
export LDFLAGS="-L$SDKROOT/usr/lib/"
./configure prefix=$PNG_LIB_DIR –enable-shared –enable-static \
CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-$GCC_VERSION LD=$DEVROOT/usr/bin/ld –host=arm-apple-darwin
make
make install
# cp the static + shared library
cp $PNG_LIB_DIR/lib/$LIBPATH_png $LIB_DIR/libpng.a.arm
cp $PNG_LIB_DIR/lib/libpng12.0.dylib $LIB_DIR/png_arm_dylib/libpng.dylib
make distclean
#######################################################
############ INTEL ###########################
#######################################################
# Use default environment
export CC=$U_CC
export CFLAGS="-arch $ARCH_SIM -O3"
export LD=$U_LD
export LDFLAGS=$U_LDFLAGS
export CPP=$U_CPP
export CPPFLAGS=$U_CPPFLAGS
LIBPATH_png=libpng12.a
./configure prefix=$PNG_LIB_DIR –enable-shared –enable-static –host=i686-apple-darwin9
make
make install
# cp the static library
cp $PNG_LIB_DIR/lib/$LIBPATH_png $LIB_DIR/libpng.a.i386
# cp the include/* files
cp $PNG_LIB_DIR/include/libpng12/* $LIB_DIR/include/png/
make distclean
# combine the static libraries for i386 and arm
$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/libpng.a.arm -arch $ARCH_SIM $LIB_DIR/libpng.a.i386 -create -output $LIB_DIR/libpng.a
}
function jpeg()
{
#######################################################
############ JPEG ###########################
#######################################################
cd $JPEG_DIR
LIBPATH_jpeg=libjpeg.a
LIBNAME_jpeg=`basename $LIBPATH_jpeg`
#######################################################
############ ARM ###########################
#######################################################
U_CC=$CC
U_CFLAGS=$CFLAGS
U_LD=$LD
U_LDFLAGS=$LDFLAGS
U_CPP=$CPP
U_CPPFLAGS=$CPPFLAGS
export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/$GCC_VERSION/include/ -I$SDKROOT/usr/include/"
export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -I$SDKROOT/usr/include -L$SDKROOT/usr/lib/ -O3"
export CPP="/usr/bin/cpp $CPPFLAGS"
export LDFLAGS="-L$SDKROOT/usr/lib/"
./configure prefix=$JPEG_LIB_DIR –enable-shared –enable-static \
CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-$GCC_VERSION LD=$DEVROOT/usr/bin/ld –host=arm-apple-darwin
make
make install-lib
# cp the static + shared library
cp $JPEG_LIB_DIR/lib/$LIBPATH_jpeg $LIB_DIR/$LIBNAME_jpeg.arm
cp $JPEG_LIB_DIR/lib/libjpeg.62.0.0.dylib $LIB_DIR/jpeg_arm_dylib/libjpeg.dylib
make distclean
#######################################################
############ INTEL ###########################
#######################################################
# Use default environment
export CC=$U_CC
export CFLAGS="-arch $ARCH_SIM -O3"
export LD=$U_LD
export LDFLAGS=$U_LDFLAGS
export CPP=$U_CPP
export CPPFLAGS=$U_CPPFLAGS
./configure prefix=$JPEG_LIB_DIR –enable-shared –enable-static –host=i686-apple-darwin9
make
make install-lib
# cp the static library
cp $JPEG_LIB_DIR/lib/$LIBPATH_jpeg $LIB_DIR/$LIBNAME_jpeg.i386
# cp the include/* files
cp $JPEG_LIB_DIR/include/*.h $LIB_DIR/include/jpeg/
make distclean
# combine the static libraries for i386 and arm
$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/$LIBNAME_jpeg.arm -arch $ARCH_SIM $LIB_DIR/$LIBNAME_jpeg.i386 -create -output $LIB_DIR/$LIBNAME_jpeg
}
function tiff()
{
########################################################
############# TIFF ############################
########################################################
cd $TIFF_DIR
LIBPATH_tiff=libtiff.a
LIBNAME_tiff=`basename $LIBPATH_tiff`
if [ "$1" == "arm" ]; then
#######################################################
############ ARM ###########################
#######################################################
U_CC=$CC
U_CFLAGS=$CFLAGS
U_LD=$LD
U_LDFLAGS=$LDFLAGS
U_CPP=$CPP
U_CPPFLAGS=$CPPFLAGS
export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/$GCC_VERSION/include/ -I$SDKROOT/usr/include/"
export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -I$SDKROOT/usr/include -L$SDKROOT/usr/lib/ -O3"
export CPP="/usr/bin/cpp $CPPFLAGS"
export LDFLAGS="-L$SDKROOT/usr/lib/"
./configure prefix=$TIFF_LIB_DIR CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-$GCC_VERSION \
LD=$DEVROOT/usr/bin/ld –host=arm-apple-darwin –disable-cxx \
&& make \
&& make install
# cp the static + shared library
cp $TIFF_LIB_DIR/lib/$LIBPATH_tiff $LIB_DIR/$LIBNAME_tiff.arm
cp $TIFF_LIB_DIR/lib/libtiff.3.dylib $LIB_DIR/tiff_arm_dylib/libtiff.dylib
make distclean
elif [ "$1" == "$ARCH_SIM" ]; then
#######################################################
############ INTEL ###########################
#######################################################
# Use default environment
export CC=$U_CC
export CFLAGS="-arch $ARCH_SIM"
export LD=$U_LD
export LDFLAGS=$U_LDFLAGS
export CPP=$U_CPP
export CPPFLAGS=$U_CPPFLAGS
./configure prefix=$TIFF_LIB_DIR –host=i686-apple-darwin9 –disable-cxx \
&& make \
&& make install
# cp the static library
cp $TIFF_LIB_DIR/lib/$LIBPATH_tiff $LIB_DIR/$LIBNAME_tiff.i386
# cp the include/* files
cp $TIFF_LIB_DIR/include/*.h $LIB_DIR/include/tiff/
make distclean
# combine the static libraries for i386 and arm
$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/$LIBNAME_tiff.arm -arch $ARCH_SIM $LIB_DIR/$LIBNAME_tiff.i386 -create -output $LIB_DIR/$LIBNAME_tiff
fi
}
function im()
{
#######################################################
############ IMAGEMAGICK #######################
#######################################################
cd $IM_DIR
# static library that will be generated
LIBPATH_static=$IM_LIB_DIR/lib/libMagickCore.a
LIBNAME_static=`basename $LIBPATH_static`
LIBPATH_static2=$IM_LIB_DIR/lib/libMagickWand.a
LIBNAME_static2=`basename $LIBPATH_static2`
#######################################################
############ ARM ###########################
#######################################################
# Save relevant environment
U_CC=$CC
U_CFLAGS=$CFLAGS
U_LD=$LD
U_LDFLAGS=$LDFLAGS
U_CPP=$CPP
U_CPPFLAGS=$CPPFLAGS
export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/$GCC_VERSION/include/ -I$SDKROOT/usr/include/"
export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -I$SDKROOT/usr/include -I$LIB_DIR/include -O3"
export LDFLAGS="-L$LIB_DIR/jpeg_arm_dylib/ -L$LIB_DIR/png_arm_dylib/ -L$LIB_DIR/tiff_arm_dylib/ -L$SDKROOT/usr/lib/"
export CPP="/usr/bin/cpp $CPPFLAGS"
export CXXFLAGS="-O3 -Wall -W -D_THREAD_SAFE"
# configure to have the static libraries and make
./configure prefix=$IM_LIB_DIR CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-$GCC_VERSION LD=$DEVROOT/usr/bin/ld –host=arm-apple-darwin \
–disable-largefile –with-quantum-depth=8 –without-magick-plus-plus –without-perl –without-x –without-freetype \
–disable-shared
# compile ImageMagick
make
make install
# copy the CORE + WAND libraries – ARM version
cp $LIBPATH_static $LIB_DIR/$LIBNAME_static.arm
cp $LIBPATH_static2 $LIB_DIR/$LIBNAME_static2.arm
# clean the ImageMagick build
make distclean
#######################################################
############ INTEL ###########################
#######################################################
# Use default environment
export CC=$U_CC
export CFLAGS="-arch $ARCH_SIM -O3"
export LD=$U_LD
export LDFLAGS=$U_LDFLAGS
export CPP=$U_CPP
export CPPFLAGS=$U_CPPFLAGS
# configure with standard parameters
./configure prefix=$IM_LIB_DIR –host=i686-apple-darwin9 –without-magick-plus-plus –without-perl –without-x –without-freetype –disable-shared
# compile ImageMagick
make
make install
# copy the CORE + WAND libraries – INTEL version
cp $LIBPATH_static $LIB_DIR/$LIBNAME_static.i386
cp $LIBPATH_static2 $LIB_DIR/$LIBNAME_static2.i386
# copy the wand/ + core/ headers
cp $IM_LIB_DIR/include/ImageMagick/magick/* $LIB_DIR/include/magick/
cp $IM_LIB_DIR/include/ImageMagick/wand/* $LIB_DIR/include/wand/
# clean the ImageMagick build
make distclean
# combine the two generated libraries to be used both in the simulator and in the device
$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/$LIBNAME_static.arm -arch $ARCH_SIM $LIB_DIR/$LIBNAME_static.i386 -create -output $LIB_DIR/$LIBNAME_static
$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/$LIBNAME_static2.arm -arch $ARCH_SIM $LIB_DIR/$LIBNAME_static2.i386 -create -output $LIB_DIR/$LIBNAME_static2
}
png
jpeg
tiff "arm"
tiff "$ARCH_SIM"
im
about 5 months ago
I’m getting this exact error, and the script below from Verdier Christophe doesn’t work for me. I’m using Leopard 10.5.7, not Snow. Any help would be appreciated.
about 6 months ago
Hi,
My link and build seem to go fine – but at runtime I get this exception message:
[Session started at 2009-08-23 21:26:59 -0400.]
dyld: Symbol not found: _CFXMLNodeGetInfoPtr
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
Any idea why?
AFAIK, I’m running the latest versions of Xcode, Mac OS X, and your files.
about 6 months ago
Maybe it’ a stupid question, but will the use of ImageMagick lead to problems with the AppStore?
about 6 months ago
No, I’ve been using it in one application that it’s currently on the AppStore (Who Am I?)
about 7 months ago
hey cloud
do u have universal binary for libtiff
need that urgently.
will be great if you can share script or the library itself.
about 7 months ago
@sachin: working on it right now, stay tuned for the complete distribution ready for use.
about 7 months ago
he cloud
Dont we need magic++ if we are working with objective c.
basically if i am writing a wrapper (mm) class i will need to call c++ functionality.
about 7 months ago
@sachin: no, you can work with C ImageMagick, please look at the latest post where you can download a full XCode project to help you getting started with ImageMagick and Objective-C integration.
For TIFF support I will look at it most likely when I come home from my holidays.
about 7 months ago
hi cloud .. can you help me with of how to convert jpg image to tif using imageMagic library.
A quich help would be appritiated.
Also what is entry points to imageMagic from code.
I am working on objective c.
about 7 months ago
That would be great! I got it running in the simulator now, but not the ARM version… Enjoy your vacation!
about 7 months ago
Hey thanks for your script and of course for the Xcode project! I’m pretty new to Xcode/iPhone programming. Could you please give me a hint on what I’d have to do to get LIBTIFF into my iPhone project?
about 7 months ago
@Mario: I’ll have a look at cross-compiling libtiff and if everything works fine I’ll update the script and the XCode project (I’m on vacation so it might take a few days, I’ll email you once that is done!)
about 8 months ago
Do you have a sample iPhone project with the libraries? BTW, thanks for the “compiled package”. The script did not libMagick*.a.arm files.
about 8 months ago
@Tom: I will provide you with an example XCode project. – will mail you once it’s up!
about 8 months ago
can you please send me an email for “out of the blog “conversation, keeping it private of course
thanks
about 8 months ago
@TonTon: thank you! Done, it’s fixed now!
about 8 months ago
hello the link to jpeg patched source is down can you please update?
thanks 4 all
about 9 months ago
Wow, nevermind, figured it all out. :)
about 9 months ago
Thanks! I’ve been looking all over for something like this. Any notes on how to implement this once it’s added to a project? i.e. maybe how to load an image and get a histogram?
about 2 weeks ago
I’ve sent you an email. Let’s see if we can fix this!
Regards,
~C