Getting LibCurl to work on iOs... - iphone

Does anyone have any experience getting LibCurl working on iPhone OS? Any Tutorials or sample code available for getting understand all thing related to cURL for iOS Development.

You can find a sample application and static libaries at:
http://seiryu.home.comcast.net/~seiryu/libcurl-ios.html
i wasn't able to build a working xcode project to compile my own framework, so i wrote a bash script
CurlVersion="7.29.0"
export IPHONEOS_DEPLOYMENT_TARGET="4.3"
otherBuildFlags="--with-darwinssl"
rm -rf results
rm -rf Products/libcurl.framework/Versions/$CurlVersion
mkdir -p results/iOS
mkdir -p results/Sim
make clean
export CC="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc-4.2"
export CFLAGS="-arch armv7 -arch armv7s -pipe -Os -gdwarf-2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk"
export LDFLAGS="-arch armv7 -arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk"
./configure --disable-shared --enable-static --disable-dependency-tracking --host="armv7-apple-darwin" --host="armv7s-apple-darwin" $otherBuildFlags
make -j `sysctl -n hw.logicalcpu_max`
cp lib/.libs/* results/iOS/
make clean
export CC="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2"
export CFLAGS="-arch i386 -pipe -Os -gdwarf-2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk"
export CPPFLAGS="-D__IPHONE_OS_VERSION_MIN_REQUIRED=${IPHONEOS_DEPLOYMENT_TARGET%%.*}0000"
export LDFLAGS="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk"
./configure --disable-shared --enable-static --host="i386-apple-darwin" $otherBuildFlags
make -j `sysctl -n hw.logicalcpu_max`
cp lib/.libs/* results/Sim/
lipo -create results/iOS/libcurl.a results/Sim/libcurl.a -output results/libcurl.a
mkdir -p Products/libcurl.framework/Versions/$CurlVersion/Headers
mkdir -p Products/libcurl.framework/Versions/$CurlVersion/Resources
cp include/curl/*.h Products/libcurl.framework/Versions/$CurlVersion/Headers/
cp results/libcurl.a Products/libcurl.framework/Versions/$CurlVersion/
cd Products/libcurl.framework/Versions/
ln -fs $CurlVersion Current
cd ..
ln -fs Versions/Current/libcurl.a libcurl
ln -fs Versions/Current/Headers .
ln -fs Versions/Current/Resources .

Related

Matlab Mex compilation error

I’m using the Random Forest library for Matlab (link). I’m using it for classification. On Windows it works very well out of the box (precombiled mex files) but I also want to run it on a CentOS cluster.
I have tried to compile it on the cluster by executing make mex but I’m getting an error. The output is as follows:
rm twonorm_test -rf
rm tempbuild/*.o *.o -rf
rm *~ -rf
rm *.mexw32 twonorm_test -rf
rm *.mexa64 -rf
rm classRF -rf
rm *.exe -rf
echo 'Compiling classTree.cpp'
Compiling classTree.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/classTree.cpp -o tempbuild/classTree.o
echo 'Compiling Cokus (random number generator)'
Compiling Cokus (random number generator)
g++ -fpic -O2 -funroll-loops -msse3 -c src/cokus.cpp -o tempbuild/cokus.o
echo 'Compiling rfsub.f (fortran subroutines)'
Compiling rfsub.f (fortran subroutines)
gfortran -O2 -fpic -c src/rfsub.f -o rfsub.o
echo 'Compiling rfutils.cpp'
Compiling rfutils.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/rfutils.cpp -o tempbuild/rfutils.o
echo 'Generating Mex'
Generating Mex
mex src/mex_ClassificationRF_train.cpp src/classRF.cpp tempbuild/classTree.o tempbuild/rfutils.o rfsub.o tempbuild/cokus.o -o mexClassRF_train -lgfortran -lm -DMATLAB -g
Unknown MEX argument '-o'.
make: *** [mex_classRF] Error 255
Does somebody knows how to solve this issue? If you want, you can take RF_MexStandalone-v0.02.zip from the above link and then go to randomforest-matlab/RF_Reg_C/Makefile.
Edit: I have change -o to -output but now the output is the following:
rm twonorm_test -rf
rm tempbuild/*.o *.o -rf
rm *~ -rf
rm *.mexw32 twonorm_test -rf
rm *.mexa64 -rf
rm classRF -rf
rm *.exe -rf
echo 'Compiling classTree.cpp'
Compiling classTree.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/classTree.cpp -o tempbuild/classTree.o
echo 'Compiling Cokus (random number generator)'
Compiling Cokus (random number generator)
g++ -fpic -O2 -funroll-loops -msse3 -c src/cokus.cpp -o tempbuild/cokus.o
echo 'Compiling rfsub.f (fortran subroutines)'
Compiling rfsub.f (fortran subroutines)
gfortran -O2 -fpic -c src/rfsub.f -o rfsub.o
echo 'Compiling rfutils.cpp'
Compiling rfutils.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/rfutils.cpp -o tempbuild/rfutils.o
echo 'Generating Mex'
Generating Mex
mex src/mex_ClassificationRF_train.cpp src/classRF.cpp tempbuild/classTree.o tempbuild/rfutils.o rfsub.o tempbuild/cokus.o -output mexClassRF_train -lgfortran -lm -DMATLAB -g
Building with 'g++'.
cc1plus: error: unrecognized command line option "-std=c++11"
make: *** [mex_classRF] Error 255
I did not find an option -std=c++11 in the makefile.
The error is quite self-explanatory: the option -o is not recognized. If you type mex -help you see the options mex accepts. Try to replace -o with -output.
EDIT regarding the std=c++11 option, you are probably using an old version of gcc compiler. You can either change it to std=c++0x which is the equivalent option (but note that some features of the c++11 standard may not be present\implemented), or upgrade to an up-to-date version of gcc.
If you need more help, please report the output of g++ --version.

Build ICU for 64 bit iOS

I'm trying to move my app to 64 bit arm processors (and 64 bit simulator), and for that I need to recompile the ICU library (49).
After three days I reached the point where the library compiles fine, and the script I'm using puts together various architectures into one (snippet):
# ...
#x86_64
DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
SDKROOT=$DEVROOT/SDKs/iPhoneSimulator7.0.sdk
SYSROOT=$SDKROOT
export CFLAGS="-I$SDKROOT/usr/include/ -I./include/ $ICU_FLAGS -arch x86_64 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=7.0 -O3 -DU_HAVE_GCC_ATOMICS=0"
export CXXFLAGS="$CFLAGS"
export CC="$TOOLCHAINSROOT/usr/bin/clang"
export CXX="$TOOLCHAINSROOT/usr/bin/clang++"
export LDFLAGS="-L$SDKROOT/usr/lib/ -isysroot $SDKROOT -Wl,-dead_strip -miphoneos-version-min=7.0"
mkdir -p $BUILDDIR/iosbuild/x86_64
cd $BUILDDIR/iosbuild/x86_64
gnumake clean
sh $ICU_PATH/source/configure --host=arm-apple-darwin --enable-static --disable-shared -with-cross-build=$BUILDDIR/hostbuild --prefix=$BUILDDIR/iosbuild/x86_64 --with-data-packaging=library
gnumake
gnumake clean install
# ...
#x86_64
mkdir -p ${BUILDDIR}/iosbuild/x86_64/lib/libicudata
cd ${BUILDDIR}/iosbuild/x86_64/lib/libicudata
ar -x "${BUILDDIR}/iosbuild/x86_64/lib/libicudata.a"
mkdir -p ${BUILDDIR}/iosbuild/x86_64/lib/libicui18n
cd ${BUILDDIR}/iosbuild/x86_64/lib/libicui18n
ar -x "${BUILDDIR}/iosbuild/x86_64/lib/libicui18n.a"
mkdir -p ${BUILDDIR}/iosbuild/x86_64/lib/libicuio
cd ${BUILDDIR}/iosbuild/x86_64/lib/libicuio
ar -x "${BUILDDIR}/iosbuild/x86_64/lib/libicuio.a"
mkdir -p ${BUILDDIR}/iosbuild/x86_64/lib/libicule
cd ${BUILDDIR}/iosbuild/x86_64/lib/libicule
ar -x "${BUILDDIR}/iosbuild/x86_64/lib/libicule.a"
mkdir -p ${BUILDDIR}/iosbuild/x86_64/lib/libiculx
cd ${BUILDDIR}/iosbuild/x86_64/lib/libiculx
ar -x "${BUILDDIR}/iosbuild/x86_64/lib/libiculx.a"
mkdir -p ${BUILDDIR}/iosbuild/x86_64/lib/libicutest
cd ${BUILDDIR}/iosbuild/x86_64/lib/libicutest
ar -x "${BUILDDIR}/iosbuild/x86_64/lib/libicutest.a"
mkdir -p ${BUILDDIR}/iosbuild/x86_64/lib/libicutu
cd ${BUILDDIR}/iosbuild/x86_64/lib/libicutu
ar -x "${BUILDDIR}/iosbuild/x86_64/lib/libicutu.a"
mkdir -p ${BUILDDIR}/iosbuild/x86_64/lib/libicuuc
cd ${BUILDDIR}/iosbuild/x86_64/lib/libicuuc
ar -x "${BUILDDIR}/iosbuild/x86_64/lib/libicuuc.a"
ar -qc ${BUILDDIR}/iosbuild/x86_64/lib/libcombinedicu.a ${BUILDDIR}/iosbuild/x86_64/lib/libicudata/*.o ${BUILDDIR}/iosbuild/x86_64/lib/libicudata/*.ao ${BUILDDIR}/iosbuild/x86_64/lib/libicuuc/*.ao ${BUILDDIR}/iosbuild/x86_64/lib/libicui18n/*.ao ${BUILDDIR}/iosbuild/x86_64/lib/libicuio/*.ao ${BUILDDIR}/iosbuild/x86_64/lib/libicule/*.ao ${BUILDDIR}/iosbuild/x86_64/lib/libiculx/*.ao ${BUILDDIR}/iosbuild/x86_64/lib/libicutest/*.ao ${BUILDDIR}/iosbuild/x86_64/lib/libicutu/*.ao ${BUILDDIR}/iosbuild/x86_64/lib/libicuuc/*.ao
# ...
#put them together
lipo -create -arch x86_64 "${BUILDDIR}/iosbuild/x86_64/lib/libcombinedicu.a"
-arch i386 "${BUILDDIR}/iosbuild/i386/lib/libcombinedicu.a"
"${BUILDDIR}/iosbuild/arm64/lib/libcombinedicu.a"
"${BUILDDIR}/iosbuild/armv7s/lib/libcombinedicu.a"
-arch armv7 "${BUILDDIR}/iosbuild/armv7/lib/libcombinedicu.a"
-o "$FRAMEWORK_DIR/Versions/Current/$FRAMEWORK_NAME"
The problem is, when I'm compiling the app from XCode (for the 64 bit simulator), I get the following errors regarding the built ICU framework:
ld: warning: directory not found for option '-F"/Users/gliptak/ac/m-220/Sources/VBExplorer/BIMxPro/../BIMxEngine/extern/icu"'
duplicate symbol _OSAtomicIncrement32 in:
/Users/gliptak/ac/m-220/Sources/VBExplorer/BIMxEngine/extern/icu/ICU.framework/ICU(unistr.ao)
/Users/gliptak/ac/m-220/Sources/VBExplorer/BIMxEngine/extern/icu/ICU.framework/ICU(mutex.ao)
duplicate symbol _OSAtomicIncrement32Barrier in:
/Users/gliptak/ac/m-220/Sources/VBExplorer/BIMxEngine/extern/icu/ICU.framework/ICU(unistr.ao)
/Users/gliptak/ac/m-220/Sources/VBExplorer/BIMxEngine/extern/icu/ICU.framework/ICU(mutex.ao)
duplicate symbol _OSAtomicDecrement32 in:
/Users/gliptak/ac/m-220/Sources/VBExplorer/BIMxEngine/extern/icu/ICU.framework/ICU(unistr.ao)
/Users/gliptak/ac/m-220/Sources/VBExplorer/BIMxEngine/extern/icu/ICU.framework/ICU(mutex.ao)
duplicate symbol _OSAtomicDecrement32Barrier in:
/Users/gliptak/ac/m-220/Sources/VBExplorer/BIMxEngine/extern/icu/ICU.framework/ICU(unistr.ao)
/Users/gliptak/ac/m-220/Sources/VBExplorer/BIMxEngine/extern/icu/ICU.framework/ICU(mutex.ao)
...
ld: 64 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
As far as I can tell the mentioned functions are declared in system headers, and are not inline, so how can this error exist?
Do you have any ideas what I might do wrong?
UPDATE: indeed, those functions are static inline, so they cause the problem. So the question is now how do I avoid duplication?
UPDATE: tried the -std=gnu89 flag for the C compiler, no effect...
Found a solution here (confirmed working building on/for Mavericks). Could also be resolved using SVN trunk of icu4c, since that uses C++11 barriers instead.

How can I get pkg-config to work within eclipse juno (Mac OS X)?

I try to get gtkmm running within eclipse. This is my makefile (without the cleaning):
all : main.cpp
#export PATH+=/opt/local/bin;
#echo PATH=$(PATH);
g++ -v `pkg-config gtkmm-2.4 --cflags` \
-O0 -g3 -Wall -S \
-o main.o main.cpp;
g++ -v -o main.exe main.o \
`pkg-config gtkmm-2.4 \
--libs` ;
In the Console I get (amongst other output):
PATH=/usr/bin:/bin:/usr/sbin:/sbin
g++ -v `pkg-config gtkmm-2.4 --cflags` \
-O0 -g3 -Wall -S \
-o main.o main.cpp;
/bin/sh: pkg-config: command not found
I did:
ln -s /usr/bin/pkg-config /opt/local/bin/pkg-config
And when I type
/usr/bin/pkg-config
in Terminal, I get:
Must specify package names on the command line
So I assume pkg-config works in the "Terminal" ... But not in eclipse.
What can I do?
Thanks!
Nils
I don't know exactly what solved my Problem, since now, it works.
I guess it was one of the following:
makefile now looks like this:
all: main.cpp
g++ -v `pkg-config gtkmm-2.4 --cflags`-O0 -g3 -Wall -c -o main.o main.cpp;
g++ -v -o main.exe main.o `pkg-config gtkmm-2.4 --libs`
clean:
rm -f main.exe main.o
I have smybolic link towards pkg-config within /bin:
sudo ln -s /opt/local/bin/pkg-config /bin/pkg-config
I installed XQuartz
I updated MacPorts and all outdated ports:
sudo port -v selfupdate
sudo port upgrade outdated

xcodebuild not finding gcc 4.2

I am trying to run xcodebuild and I am getting the following error:
2011-12-11 04:42:22.834 xcodebuild[9155:4203] error: Error Domain=NSPOSIXErrorDomain Code=2 "Non-zero exit code 127 returned from shell command: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2 -v -E -dM -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -x objective-c -c /dev/null 2>&1" UserInfo=0x4001a61a0 {NSLocalizedDescription=Non-zero exit code 127 returned from shell command: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2 -v -E -dM -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -x objective-c -c /dev/null 2>&1, NSLocalizedFailureReason=No such file or directory}
2011-12-11 04:42:22.835 xcodebuild[9155:4203] Warning: Couldn't discover the 'gcc-4.2' compiler's built-in search paths and preprocessor definitions for language dialect 'objective-c'.
Compiler: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2
Reason: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2 -v -E -dM -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -x objective-c -c /dev/null 2>&1
2011-12-11 04:42:22.895 xcodebuild[9155:4203] error: Error Domain=NSPOSIXErrorDomain Code=2 "Non-zero exit code 127 returned from shell command: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2 -v -E -dM -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -x c -c /dev/null 2>&1" UserInfo=0x4013cbb80 {NSLocalizedDescription=Non-zero exit code 127 returned from shell command: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2 -v -E -dM -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -x c -c /dev/null 2>&1, NSLocalizedFailureReason=No such file or directory}
2011-12-11 04:42:22.900 xcodebuild[9155:4203] Warning: Couldn't discover the 'gcc-4.2' compiler's built-in search paths and preprocessor definitions for language dialect 'c'.
Compiler: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2
Reason: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2 -v -E -dM -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -x c -c /dev/null 2>&1
Any idea why this is? I am guessing that it is because I don't have gcc-4.2 in the following path:
/Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2
as of right now gcc-4.2 is located at usr/bin. The question is how do I redirect it?
This could be be related to your $CC variable in your shell ( it keeps track of your compiler ) you can find more information from jMoody on github
Essentially you need to remove $CC
How did you select the compiler? Go to the Xcode navigator, click on the upmost item, then in the right window on your project (not the target), then Build Settings. U and in the section Build Options you can select the compiler. Usually you can choose between LLVM gcc-4.x and some Apple LLVM x.
Have you used xcode-select to select the version of Xcode you want to use?
Manpage.

problem compiling ffmpeg for iFrameExtractor

I'm trying to compile the ffmpeg by using the make and build files in iFrameExtractor example. firstly i tried to follow the readme file on the github, which only says to run the ./build_universal in ffmpeg folder. it did not work
i then tried to follow the info in INSTALL without success. i then tried doing the stuff in INSTALL followed by the ./build_universal which didn't work. All the *.a files that are imported to the project exists until the end of the build sequence. when the lipo commands in build_universal are run, which i guess concat the .a files for the different architectures(?). anyhow these leave the following errors:
lipo: specifed architecture type (armv6) for file (armv6/libavcodec.a) does not match it's cputype (16777223) and cpusubtype (3) (should be cputype (12) and cpusubtype (6))
lipo: specifed architecture type (armv6) for file (armv6/libavdevice.a) does not match it's cputype (16777223) and cpusubtype (3) (should be cputype (12) and cpusubtype (6))
lipo: specifed architecture type (armv6) for file (armv6/libavformat.a) does not match it's cputype (16777223) and cpusubtype (3) (should be cputype (12) and cpusubtype (6))
lipo: specifed architecture type (armv6) for file (armv6/libavutil.a) does not match it's cputype (16777223) and cpusubtype (3) (should be cputype (12) and cpusubtype (6))
lipo: specifed architecture type (armv6) for file (armv6/libswscale.a) does not match it's cputype (16777223) and cpusubtype (3) (should be cputype (12) and cpusubtype (6))
i can get the project to compile for simulator if i only use ./build_armv7 but if i run the universal the .a files are removed in the end. and only using doesn't work to build for iphone 4 .
After a week of trial and error, I was finally able to create the ffmpeg universal libraries and successfully compile and run iFrameExtractor for the device as well as the simulator.
To compile and run the project on your iPhone device OR simulator:
1) open Terminal
2) clone the repository: git clone git://github.com/lajos/iFrameExtractor.git
3) go to the ffmpeg folder in the project: cd iFrameExtractor/ffmpeg
4) run: ./configure
5) Edit the build scripts (build_armv6, build_armv7, build_i386) as follows:
These scripts assume you are using iOS SDK 5.0 on Xcode 4.2.
build_armv6:
#!/bin/tcsh -f
if (! -d armv6) mkdir armv6
if (! -d lib) mkdir lib
rm armv6/*.a
make clean
./configure \
--disable-bzlib --disable-doc \
--disable-ffmpeg --disable-ffplay \
--disable-ffserver --disable-mmx \
--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--as='gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' \
--enable-cross-compile --target-os=darwin \
--arch=arm --cpu=arm1176jzf-s \
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk \
--extra-ldflags="-arch armv6 -L//Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/system" \
--extra-cflags="-arch armv6"
make
mv libavcodec/libavcodec.a armv6/
mv libavdevice/libavdevice.a armv6/
mv libavformat/libavformat.a armv6/
mv libavutil/libavutil.a armv6/
mv libswscale/libswscale.a armv6/
rm lib/*.a
cp armv6/*.a lib/
build_armv7:
#!/bin/tcsh -f
if (! -d armv7) mkdir armv7
if (! -d lib) mkdir lib
rm armv7/*.a
make clean
./configure \
--disable-bzlib --disable-doc \
--disable-ffmpeg --disable-ffplay \
--disable-ffserver --disable-mmx \
--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--as='gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' \
--enable-cross-compile --target-os=darwin \
--arch=arm --cpu=cortex-a8 --enable-pic \
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk \
--extra-ldflags="-arch armv7 - L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/system" \
--extra-cflags="-arch armv7"
make
mv libavcodec/libavcodec.a armv7/
mv libavdevice/libavdevice.a armv7/
mv libavformat/libavformat.a armv7/
mv libavutil/libavutil.a armv7/
mv libswscale/libswscale.a armv7/
rm lib/*.a
cp armv7/*.a lib/
build_i386:
#!/bin/tcsh -f
if (! -d i386) mkdir i386
if (! -d lib) mkdir lib
rm i386/*.a
make clean
./configure \
--disable-bzlib --disable-doc \
--disable-ffmpeg --disable-ffplay \
--disable-ffserver --disable-mmx \
--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--as='gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' \
--sysroot=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk \
--extra-ldflags="-arch i386 -L//Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/usr/lib/system" \
--extra-cflags="-arch i386 -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -O0 -fasm-blocks -Wreturn-type -Wunused-variable -D__IPHONE_OS_VERSION_MIN_REQUIRED=40000 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -fvisibility=hidden -mmacosx-version-min=10.5 -gdwarf-2"
make
mv libavcodec/libavcodec.a i386/
mv libavdevice/libavdevice.a i386/
mv libavformat/libavformat.a i386/
mv libavutil/libavutil.a i386/
mv libswscale/libswscale.a i386/
rm lib/*.a
cp i386/*.a lib/
6) build the ffmpeg libraries: ./build_universal
7) open the xcode project and run it on your iPhone device or simulator
These steps work perfectly for me. I hope this will help others struggling to get the ffmpeg libraries working for iOS.
i downloaded the latest ffmpeg repository and used the following to compile only for armv6 and armv7. I couldn't get it working for i386, i receive errors that the cputype and subcputype are wrong. apparently the cputype is supposed to be x86 and subcputype should be intel.
anyhow i used the following build scripts to compile for the arm architectures:
build script:
#!/bin/sh
set -e
SCRIPT_DIR=$( (cd -P $(dirname $0) && pwd) )
DIST_DIR_BASE=${DIST_DIR_BASE:="$SCRIPT_DIR/dist"}
if [ -d ffmpeg ]
then
echo "Found ffmpeg source directory, no need to fetch from git..."
else
echo "Fetching ffmpeg from git://git.videolan.org/ffmpeg.git..."
git clone git://git.videolan.org/ffmpeg.git
fi
ARCHS=${ARCHS:-"armv6 armv7"}
for ARCH in $ARCHS
do
FFMPEG_DIR=ffmpeg-$ARCH
if [ -d $FFMPEG_DIR ]
then
echo "Removing old directory $FFMPEG_DIR"
rm -rf $FFMPEG_DIR
fi
echo "Copying source for $ARCH to directory $FFMPEG_DIR"
cp -a ffmpeg $FFMPEG_DIR
cd $FFMPEG_DIR
DIST_DIR=$DIST_DIR_BASE-$ARCH
mkdir -p $DIST_DIR
case $ARCH in
armv6)
EXTRA_FLAGS="--enable-cross-compile --target-os=darwin --arch=arm --cpu=arm1176jzf-s"
EXTRA_CFLAGS="-arch $ARCH"
EXTRA_LDFLAGS="-arch $ARCH"
;;
armv7)
EXTRA_FLAGS="--enable-cross-compile --target-os=darwin --arch=arm --cpu=cortex-a8 --enable-pic"
EXTRA_CFLAGS="-arch $ARCH"
EXTRA_LDFLAGS="-arch $ARCH"
;;
x86_64)
EXTRA_CC_FLAGS="-mdynamic-no-pic"
;;
esac
echo "Configuring ffmpeg for $ARCH..."
./configure \
--prefix=$DIST_DIR \
--extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/system \
--disable-bzlib \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk \
--extra-ldflags="$EXTRA_LDFLAGS" \
--extra-cflags="$EXTRA_CFLAGS" \
$EXTRA_FLAGS
echo "Installing ffmpeg for $ARCH..."
make && make install
cd $SCRIPT_DIR
if [ -d $DIST_DIR/bin ]
then
rm -rf $DIST_DIR/bin
fi
if [ -d $DIST_DIR/share ]
then
rm -rf $DIST_DIR/share
fi
done
and combine libs script:
#!/bin/bash
set -e
ARCHS="armv6 armv7"
for ARCH in $ARCHS
do
if [ -d dist-$ARCH ]
then
MAIN_ARCH=$ARCH
fi
done
if [ -z "$MAIN_ARCH" ]
then
echo "Please compile an architecture"
exit 1
fi
OUTPUT_DIR="dist-uarch"
rm -rf $OUTPUT_DIR
mkdir -p $OUTPUT_DIR/lib $OUTPUT_DIR/include
for LIB in dist-$MAIN_ARCH/lib/*.a
do
LIB=`basename $LIB`
LIPO_CREATE=""
for ARCH in $ARCHS
do
if [ -d dist-$ARCH ]
then
LIPO_CREATE="$LIPO_CREATE-arch $ARCH dist-$ARCH/lib/$LIB "
fi
done
OUTPUT="$OUTPUT_DIR/lib/$LIB"
echo "Creating: $OUTPUT"
lipo -create $LIPO_CREATE -output $OUTPUT
lipo -info $OUTPUT
done
echo "Copying headers from dist-$MAIN_ARCH..."
cp -R dist-$MAIN_ARCH/include/* $OUTPUT_DIR/include
then i import the .a files from BUILD-FOLDER/dist-uarch and it builds in xcode like a charm!
building FFMPEG for iOS 5.1
hope this will help you to build latest FFMPEG for iOS 5.1
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
./build_universal
note: you have to create build_* scripts first, to do this see code below
script for ARMV7 - create file build_armv7
#!/bin/tcsh -f
if (! -d armv7) mkdir armv7
if (! -d lib) mkdir lib
rm armv7/*.a
make clean
./configure --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffserver --enable-cross-compile --arch=arm --target-os=darwin --cc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc --as='gas-preprocessor.pl /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk --cpu=cortex-a8 --extra-cflags='-arch armv7' --extra-ldflags='-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk' --enable-pic
make
mv libavcodec/libavcodec.a armv7/
mv libavdevice/libavdevice.a armv7/
mv libavformat/libavformat.a armv7/
mv libavutil/libavutil.a armv7/
mv libswscale/libswscale.a armv7/
rm lib/*.a
cp armv7/*.a lib/
script for ARMV6 - create file build_armv6
#!/bin/tcsh -f
if (! -d armv6) mkdir armv6
if (! -d lib) mkdir lib
rm armv6/*.a
make clean
./configure --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffserver --enable-cross-compile --arch=arm --target-os=darwin --cc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc --as='gas-preprocessor.pl /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk --cpu=arm1176jzf-s --extra-cflags='-arch armv6' --extra-ldflags='-arch armv6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk'
make
mv libavcodec/libavcodec.a armv6/
mv libavdevice/libavdevice.a armv6/
mv libavformat/libavformat.a armv6/
mv libavutil/libavutil.a armv6/
mv libswscale/libswscale.a armv6/
rm lib/*.a
cp armv6/*.a lib/
script for simulator - create file build_i386
#!/bin/tcsh -f
if (! -d i386) mkdir i386
if (! -d lib) mkdir lib
rm i386/*.a
make clean
./configure \
--disable-bzlib --disable-doc \
--disable-ffmpeg --disable-ffplay \
--disable-ffserver --disable-mmx \
--cc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--as='gas-preprocessor.pl /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' \
--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk \
--extra-ldflags="-arch i386 -L//Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/usr/lib/system" \
--extra-cflags="-arch i386 -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -O0 -fasm-blocks -Wreturn-type -Wunused-variable -D__IPHONE_OS_VERSION_MIN_REQUIRED=40000 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -fvisibility=hidden -mmacosx-version-min=10.5 -gdwarf-2"
make
mv libavcodec/libavcodec.a i386/
mv libavdevice/libavdevice.a i386/
mv libavformat/libavformat.a i386/
mv libavutil/libavutil.a i386/
mv libswscale/libswscale.a i386/
rm lib/*.a
cp i386/*.a lib/
script for universal build (will merge libraries into one universal) - create file build_universal
#!/bin/tcsh -f
source ./build_armv6
source ./build_armv7
source ./build_i386
if (! -d universal) mkdir universal
if (! -d lib) mkdir lib
rm universal/*.a
lipo -create -arch armv6 armv6/libavcodec.a -arch armv7 armv7/libavcodec.a -arch i386 i386/libavcodec.a -output universal/libavcodec.a
lipo -create -arch armv6 armv6/libavdevice.a -arch armv7 armv7/libavdevice.a -arch i386 i386/libavdevice.a -output universal/libavdevice.a
lipo -create -arch armv6 armv6/libavformat.a -arch armv7 armv7/libavformat.a -arch i386 i386/libavformat.a -output universal/libavformat.a
lipo -create -arch armv6 armv6/libavutil.a -arch armv7 armv7/libavutil.a -arch i386 i386/libavutil.a -output universal/libavutil.a
lipo -create -arch armv6 armv6/libswscale.a -arch armv7 armv7/libswscale.a -arch i386 i386/libswscale.a -output universal/libswscale.a
rm lib/*.a
cp universal/*.a lib/