I want to describe a detailed command line way to build librtmp and openssl in order to include in an iPhone / iOS project.
You can use this as example to build any other library.
I started from the project from saiten where all this procedure is scripted in build.sh.
We start building openssl. We need to build three version of the library:
- arm6
- arm7
- i386 for simulator
We need three version in order to create a binary compatible with the old devices and i386 for the simulator.
Download the openssl source code. (http://www.openssl.org/source/).
mkdir openssl cd openssl curl http://www.openssl.org/source/openssl-1.0.0g.tar.gz -O openssl-1.0.0g.tar.gz tar xfz openssl-1.0.0g.tar.gz
We’ll build all the release in the tmp folder.
Start to configure it for armv6.
mkdir /tmp/openssl-1.0.0g-armv6 cd openssl-1.0.0g ./configure BSD-generic32 --openssldir=/tmp/openssl-1.0.0g-armv6
Now we has to edit Makefile and change
#edit Makefile and change #CC= gcc with CC= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv6 # add to CLAGS: -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk
This links are valid for my buildsystem, using SDK 5.0. Change it to build for other buildsystem.
At this point we are ready to build.
make make install
Now in /tmp/openssl-1.0.0g-armv6 we have the builded lib.
We do the same for armv7 and i386:
#ARMV7 cd .. mkdir /tmp/openssl-1.0.0g-armv7 rm -fr openssl-1.0.0g tar xfz openssl-1.0.0g.tar.gz cd openssl-1.0.0g ./configure BSD-generic32 --openssldir=/tmp/openssl-1.0.0g-armv7 #edit Makefile and change #CC= gcc with CC= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7 #add to CLAGS: -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk make make install #i386 mkdir /tmp/openssl-1.0.0g-i386 rm -fr openssl-1.0.0g tar xfz openssl-1.0.0g.tar.gz cd openssl-1.0.0g ./configure BSD-generic32 --openssldir=/tmp/openssl-1.0.0g-i386 #edit Makefile and change #CC= gcc with CC= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch i386 #add to CLAGS: -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk make make install
At this point we can create an universal library using lipo.
cd .. mkdir include cp -r /tmp/openssl-1.0.0g-i386/include/ include/ mkdir lib lipo /tmp/openssl-1.0.0g-armv6/lib/libcrypto.a /tmp/openssl-1.0.0g-armv7/lib/libcrypto.a /tmp/openssl-1.0.0g-i386/lib/libcrypto.a -create -output lib/libcrypto.a lipo /tmp/openssl-1.0.0g-armv6/lib/libssl.a /tmp/openssl-1.0.0g-armv7/lib/libssl.a /tmp/openssl-1.0.0g-i386/lib/libssl.a -create -output lib/libssl.a
Now we have in our include and lib folder the the universal library of openssl.
To build librmtb for ios we build the three version of library like for openssl.
Starting cloning the last release
mkdir librtmp cd librtmp git clone git://git.ffmpeg.org/rtmpdump rtmpdump
To build the armv6 version of library make a copy of the source:
cp -r rtmpdump rtmpdump-armv6 cd rtmpdump-armv6/librtmp #edit Makefile and set #CC=$(CROSS_COMPILE)gcc -arch armv6 export CROSS_COMPILE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ export XCFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -I/tmp/openssl/include/ -arch armv6" export XLDFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -L/tmp/openssl/lib -arch armv6 " make SYS=darwin make SYS=darwin prefix=/tmp/librtmp-armv6 install
Change the path to export using the correct system build path and the path of the openssl lib build before.
For the armv7
cp -r rtmpdump rtmpdump-armv7 cd rtmpdump-armv7/librtmp #edit Makefile and change #CC=$(CROSS_COMPILE)gcc -arch armv7 export CROSS_COMPILE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ export XCFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -I/tmp/openssl/include/ -arch armv7" export XLDFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -L/tmp/openssl/lib -arch armv7 " make SYS=darwin make SYS=darwin prefix=/tmp/librtmp-armv7 install
For simulator
cd .. cp -r rtmpdump rtmpdump-i386 cd rtmpdump-i386/librtmp edit Makefile con CC=$(CROSS_COMPILE)gcc -arch i386 export CROSS_COMPILE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ export XCFLAGS="-isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -I/tmp/openssl/include/ -arch i386" export XLDFLAGS="-isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -L/tmp/openssl/lib -arch i386 " make SYS=darwin make SYS=darwin prefix=/tmp/librtmp-i386 install
At this point we can create an universal library using lipo.
mkdir include cp -r /tmp/librtmp-i386/include/librtmp include/ mkdir lib lipo /tmp/librtmp-armv6/lib/librtmp.a /tmp/librtmp-armv7/lib/librtmp.a /tmp/librtmp-i386/lib/librtmp.a -create -output lib/librtmp.a
Hello,
I try to follow all steps, but unfortunately have some problem with step which starts to build librtmp
The step is following
mkdir librtmp
cd librtmp
git clone git://git.ffmpeg.org/rtmpdump rtmpdump
To build the armv6 version of library make a copy of the source:
?
cp -r rtmpdump rtmpdump-armv6
cd rtmpdump-armv6/librtmp
#edit Makefile and set
#CC=$(CROSS_COMPILE)gcc -arch armv6
export CROSS_COMPILE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/
export XCFLAGS=”-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -I/tmp/openssl/include/ -arch armv6″
export XLDFLAGS=”-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -L/tmp/openssl/lib -arch armv6 ”
make SYS=darwin
Here compiler returns error…
OS version is Snow Leopard.
Please help me to understand the problem.
Thanks in advance
Sorry for the delay…I lost the reply…
What’s the compiler error?
I done all the progress,i got some files in my finder.how can i use those files into my ios coding.please help me
I’ve tried following your steps but I get make erros with crypto. I can’t completely build openssl.
Hello,
I try to follow all steps, but unfortunately have some problem with step which starts to build librtmp
The step is following
mkdir librtmp
cd librtmp
git clone git://git.ffmpeg.org/rtmpdump rtmpdump
To build the armv6 version of library make a copy of the source:
?
cp -r rtmpdump rtmpdump-armv6
cd rtmpdump-armv6/librtmp
#edit Makefile and set
#CC=$(CROSS_COMPILE)gcc -arch armv6
export CROSS_COMPILE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/
export XCFLAGS=”-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk -I/tmp/openssl/include/ -arch armv6″
export XLDFLAGS=”-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk -L/tmp/openssl/lib -arch armv6 ”
make SYS=darwin
Here compiler returns next error:
sh-3.2# export XCFLAGS=”-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk /Users/admin/librtmpSource/openssl/include/ -arch armv7″
sh-3.2# export XLDFLAGS=”-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk /Users/admin/librtmpSource/openssl/lib -arch armv7″
sh-3.2# make SYS=darwin
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk /Users/admin/librtmpSource/openssl/include/ -arch armv7 -DRTMPDUMP_VERSION=\”v2.4\” -DUSE_OPENSSL -O2 -fPIC -c -o rtmp.o rtmp.c
rtmp.c:40:25: error: openssl/ssl.h: No such file or directory
rtmp.c:41:25: error: openssl/rc4.h: No such file or directory
rtmp.c:43: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
In file included from rtmp.c:127:
handshake.h:66:25: error: openssl/sha.h: No such file or directory
handshake.h:67:26: error: openssl/hmac.h: No such file or directory
handshake.h:70:2: error: #error Your OpenSSL is too old, need 0.9.8 or newer with SHA256
In file included from rtmp.c:127:
handshake.h:76: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
In file included from handshake.h:86,
from rtmp.c:127:
dh.h:125:24: error: openssl/bn.h: No such file or directory
dh.h:126:24: error: openssl/dh.h: No such file or directory
In file included from handshake.h:86,
from rtmp.c:127:
dh.h:128: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
In file included from handshake.h:86,
from rtmp.c:127:
dh.h:155: error: expected ‘)’ before ‘y’
dh.h:205: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
dh.h:238: error: expected ‘)’ before ‘*’ token
dh.h:272: error: expected ‘)’ before ‘*’ token
dh.h:308: error: expected ‘)’ before ‘*’ token
In file included from rtmp.c:127:
handshake.h:116: error: expected declaration specifiers or ‘…’ before ‘RC4_handle’
handshake.h:116: error: expected declaration specifiers or ‘…’ before ‘RC4_handle’
handshake.h: In function ‘InitRC4Encryption’:
handshake.h:118: error: ‘SHA256_DIGEST_LENGTH’ undeclared (first use in this function)
handshake.h:118: error: (Each undeclared identifier is reported only once
handshake.h:118: error: for each function it appears in.)
handshake.h:120: error: ‘HMAC_CTX’ undeclared (first use in this function)
handshake.h:120: error: expected ‘;’ before ‘ctx’
handshake.h:122: error: ‘rc4keyIn’ undeclared (first use in this function)
handshake.h:122: error: ‘RC4_KEY’ undeclared (first use in this function)
handshake.h:123: error: ‘rc4keyOut’ undeclared (first use in this function)
handshake.h:125: warning: implicit declaration of function ‘HMAC_CTX_init’
handshake.h:125: error: ‘ctx’ undeclared (first use in this function)
handshake.h:125: warning: implicit declaration of function ‘HMAC_Init_ex’
handshake.h:125: warning: implicit declaration of function ‘EVP_sha256’
handshake.h:126: warning: implicit declaration of function ‘HMAC_Update’
handshake.h:127: warning: implicit declaration of function ‘HMAC_Final’
handshake.h:127: warning: implicit declaration of function ‘HMAC_CTX_cleanup’
handshake.h:132: warning: implicit declaration of function ‘RC4_set_key’
handshake.h:118: warning: unused variable ‘digest’
handshake.h: In function ‘HMACsha256’:
handshake.h:269: error: ‘HMAC_CTX’ undeclared (first use in this function)
handshake.h:269: error: expected ‘;’ before ‘ctx’
handshake.h:271: error: ‘ctx’ undeclared (first use in this function)
handshake.h: In function ‘CalculateDigest’:
handshake.h:282: error: ‘SHA256_DIGEST_LENGTH’ undeclared (first use in this function)
handshake.h:283: warning: unused variable ‘message’
handshake.h: In function ‘VerifyDigest’:
handshake.h:297: error: ‘SHA256_DIGEST_LENGTH’ undeclared (first use in this function)
handshake.h:297: warning: unused variable ‘calcDigest’
handshake.h: In function ‘HandShake’:
handshake.h:703: error: ‘RC4_handle’ undeclared (first use in this function)
handshake.h:703: error: expected ‘;’ before ‘keyIn’
handshake.h:704: error: expected ‘;’ before ‘keyOut’
handshake.h:772: warning: implicit declaration of function ‘DHInit’
handshake.h:772: warning: assignment makes pointer from integer without a cast
handshake.h:783: warning: implicit declaration of function ‘DHGenerateKey’
handshake.h:790: warning: implicit declaration of function ‘DHGetPublicKey’
handshake.h:806: error: ‘SHA256_DIGEST_LENGTH’ undeclared (first use in this function)
handshake.h:893: warning: implicit declaration of function ‘DHComputeSharedSecretKey’
handshake.h:907: error: ‘keyIn’ undeclared (first use in this function)
handshake.h:907: error: ‘keyOut’ undeclared (first use in this function)
handshake.h:907: error: too many arguments to function ‘InitRC4Encryption’
handshake.h:847: warning: unused variable ‘digestResp’
handshake.h:1049: warning: implicit declaration of function ‘RC4’
handshake.h:983: warning: unused variable ‘digest’
handshake.h:982: warning: unused variable ‘signature’
handshake.h: In function ‘SHandShake’:
handshake.h:1077: error: ‘RC4_handle’ undeclared (first use in this function)
handshake.h:1077: error: expected ‘;’ before ‘keyIn’
handshake.h:1078: error: expected ‘;’ before ‘keyOut’
handshake.h:1160: warning: assignment makes pointer from integer without a cast
handshake.h:1195: error: ‘SHA256_DIGEST_LENGTH’ undeclared (first use in this function)
handshake.h:1277: error: ‘keyIn’ undeclared (first use in this function)
handshake.h:1277: error: ‘keyOut’ undeclared (first use in this function)
handshake.h:1277: error: too many arguments to function ‘InitRC4Encryption’
handshake.h:1214: warning: unused variable ‘digestResp’
handshake.h:1341: warning: unused variable ‘digest’
handshake.h:1340: warning: unused variable ‘signature’
rtmp.c: In function ‘RTMP_TLS_Init’:
rtmp.c:220: warning: implicit declaration of function ‘SSL_load_error_strings’
rtmp.c:221: warning: implicit declaration of function ‘SSL_library_init’
rtmp.c:222: warning: implicit declaration of function ‘OpenSSL_add_all_digests’
rtmp.c:223: error: ‘RTMP_TLS_ctx’ undeclared (first use in this function)
rtmp.c:223: warning: implicit declaration of function ‘SSL_CTX_new’
rtmp.c:223: warning: implicit declaration of function ‘SSLv23_method’
rtmp.c:224: warning: implicit declaration of function ‘SSL_CTX_set_options’
rtmp.c:224: error: ‘SSL_OP_ALL’ undeclared (first use in this function)
rtmp.c:225: warning: implicit declaration of function ‘SSL_CTX_set_default_verify_paths’
rtmp.c: In function ‘RTMP_Init’:
rtmp.c:246: error: ‘RTMP_TLS_ctx’ undeclared (first use in this function)
rtmp.c: In function ‘RTMP_Connect1’:
rtmp.c:867: warning: implicit declaration of function ‘SSL_new’
rtmp.c:867: error: ‘RTMP_TLS_ctx’ undeclared (first use in this function)
rtmp.c:867: warning: assignment makes pointer from integer without a cast
rtmp.c:868: warning: implicit declaration of function ‘SSL_set_fd’
rtmp.c:869: warning: implicit declaration of function ‘SSL_connect’
rtmp.c: In function ‘RTMP_Close’:
rtmp.c:3535: warning: implicit declaration of function ‘DH_free’
rtmp.c: In function ‘RTMPSockBuf_Fill’:
rtmp.c:3565: warning: implicit declaration of function ‘SSL_read’
rtmp.c: In function ‘RTMPSockBuf_Send’:
rtmp.c:3608: warning: implicit declaration of function ‘SSL_write’
rtmp.c: In function ‘RTMPSockBuf_Close’:
rtmp.c:3624: warning: implicit declaration of function ‘SSL_shutdown’
rtmp.c:3625: warning: implicit declaration of function ‘SSL_free’
make: *** [rtmp.o] Error 1
OS version is Moutain Lion.
NOTE: Here the path /Users/admin/librtmpSource/openssl/include/ is a path to the lipo headers and
a path /Users/admin/librtmpSource/openssl/lib — to the lipo libs of openssl build
I follow your step and compiled successfully. Anyway when I add it to Xcode and run my program, the error has occurred as follow:
dyld: Library not loaded: /usr/local/lib/librtmp.0.dylib
Referenced from: ~/Myapp.app/Myapp
Reason: image not found
What should I do next?
@Jessie
dyld: Library not loaded: /usr/local/lib/librtmp.0.dylib
Referenced from: ~/Myapp.app/Myapp
Reason: image not found
To resolve this issue . you should try the following
Xcode tries( prefers) to load dynamic library from the location specified in “Library Search Path” over a static library( librtmp.a in this case) , so in order to resolve this error just move “librtmp.a ” to some other folder and specify that folder’s path in “Library Search Path ” under “Build Settings ” in your Xcode.
Hope this helps.