ios的make file例子

具体的例子暂时没有,下面的文章供参考:


1. x264的编译

首先到http://www.videolan.org/developers/x264.html下载x264的库,然后解压。

打开shell,进入x264的目录,执行如下语句

CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc ./configure --host=arm-apple-darwin --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk --prefix='dist' --extra-cflags='-arch armv7' --extra-ldflags='-arch armv7 -L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/system' --enable-pic

然后make,libx264.a就出来啦。如果无法执行,请将语句中的5.0.sdk替换成你电脑里面有的sdk。


2. 如何通过Makefile编译iphone的openSSL

这两天接受了一个新任务,就是学在iphone和android平台上编译openSSL,因为我对Apple知之甚少, 所以在做的过程中遇到了 一些困难和问题,经过学习和尝试,终于弄出来了,网上的好多教程有问题,所以自己根据自己的经验,写一篇博文和大家分享一下。
版本:OpenSSL 1.0.0e 
Xcode 4 with iOS 4.
注意:根目录定为我的本家目录即/Users/jianke.tang/
下面开始我们的旅程
1. 下载openSSL(http://www.openssl.org/source/),修改源代码
下载下来的以后进行解压,为了避免编译错误,需要进行稍微的修改,打开 crypto/ui/ui_openssl.c,然后将
static volatile sig_atomic_t intr_signal;
改为
static volatile int intr_signal;
2. 创建一个放置不同平台的库
$ mkdir ssllibs
3. 为i386模拟器编译openssl
$ cd openssl-1.0.0e
$ mkdir openssl_armv6 openssl_armv7 openssl_i386
$ ./Configure BSD-generic32 --openssldir=/Users/jianke.tang/openssl-1.0.0e/openssl_i386
修改Makefile文件
$ vi Makefile
a.找到
CC = cc
将其改为
CC= /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -arch i386
b.就在这行下边找到CFLAG, 在'='后面添加
-isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk
c.编译安装
$ make
$ make install
d.复制到上面建立的库中
$ cp -r openssl_i386 ../ssllibs
注:i386只有基于模拟器的,没有OS的,所以基于arm的和i386的是不一样的
4.为armv6 ios编译openSSL
$ make clean
$ ./Configure BSD-generic32 --openssldir=/Users/jianke.tang/openssl-1.0.0e/openssl_armv6
修改Makefile文件
a.找到
CC = cc
将其改为
CC= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv6
b.就在这行下边找到CFLAG, 在'='后面添加
-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk
c.编译安装
$ make
$ make install
d.复制到上面建立的库中
$ cp -r openssl_armv6 ../ssllibs
注:请注意,一定确保相关路径下有该文件,否则会出现编译错误,比如iPhoneOS4.3.sdk可能是iPhoneOS4.0.sdk版本的
5. 为armv6 ios编译openSSL5. 
$ make clean
$ ./Configure BSD-generic32 --openssldir=/Users/jianke.tang/openssl-1.0.0e/openssl_armv7
修改Makefile文件
a.找到
CC = cc
将其改为
CC= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7
b.就在这行下边找到CFLAG,在'='后面添加
-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk
c.编译安装
$ make
$ make install
d.复制到上面建立的库中
$ cp -r openssl_armv7 ../ssllibs
6. 库的处理
打开库ssllibs,在各个平台下的lib/中的libcrypto.a和libssl.a,以及在各个平台下的include文件夹
好了,我们可以创建一般性的链接库了,这样可以保证它可以根据平台自动选择。
$ lipo -create ../ssllibs/openssl_i386/lib/libcrypto.a ../ssllibs/openssl_armv6/lib/libcrypto.a openssl_armv7/lib/libcrypto.a -output ../ssllibs/libcrypto.a
$ lipo -create ../ssllibs/openssl_i386/lib/libssl.a ../ssllibs/openssl_armv6/lib/libssl.a openssl_armv7/lib/libssl.a -output ../ssllibs/libssl.a

7.到这里就大功告成了,不过为了帮助大家更更好的理解和使用,这里我教大家如何修改IPHONE-XCODE PROJECT
1. Copy the “include” folder from OpenSSL into your project-folder
2. Copy the libcrypto.a and libssl.a files into your project-folder
3. Drag the libcrypto.a and libssl.a files into your XCode Framework Folder-Tree
4. Open the Build-Info from your “Target” (Righclick on Target – Get Info)
    Change Library Search Paths to 
       $(inherited) "$(SRCROOT)"
6. Change User Header Search Paths to include
7. Activate Always Search User Paths

8. 这里有个例子工程,大家可以参考一下,别的我就不赘述了 http://github.com/x2on/OpenSSL-for-iPhone。
这个库是iOS 3.2/4.0 XCode Project with OpenSSL 1.0.0a
使用了MD5-algorithm to calculate an md5 hash from an UITextfield.



3.以samba讲解如何交叉编译开源库用于iphone平台

首先设定iphone编译环境

红色为我自定义的编译samba时候设置一些环境,可以改

1>

export LDFLAGS="-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib -L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/system"

2>

export PATH=$PATH:/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/

3>(举例编译samba库)

./configure --prefix=/Users/kanoutouyetao/samba-iphone  CC=arm-apple-darwin10-gcc-4.2.1--enable-static --without-readline --with-libsmbclient CPPFLAGS="-I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/gcc/arm-apple-darwin10/4.2.1/include -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/include" --host=arm-apple-darwin10 --build=x86

在./configure中出现 cannot run test program while cross compiling

错误修改之:
cannot run test program while cross compiling
修改以下文件:

+,表示添加

-,表示减去
1】
--- samba-3.3.3/source/configure       
+ ../c-programm/samba-3.3.3/source/configure 
 
 { $as_echo "$as_me:$LINENO: checking that the C compiler understands negative enum values" >&5
 $as_echo_n "checking that the C compiler understands negative enum values... " >&6; }
+samba_cv_CC_NEGATIVE_ENUM_VALUES=stz(加入)
 if test "${samba_cv_CC_NEGATIVE_ENUM_VALUES+set}" = set; then
   $as_echo_n "(cached) " >&6
 Else
2】先运行configure后,在修改
--- samba-3.3.3/source/include/config.h
+++ ../c-programm/samba-3.3.3/source/include/config.h   


-#define HAVE_LBER_H 1
+#define HAVE_LBER_H 0

-#define HAVE_LBER_LOG_PRINT_FN 1
+#define HAVE_LBER_LOG_PRINT_FN 0

-#define HAVE_LDAP_H 1
+#define HAVE_LDAP_H 0

./configure

make

(说明,因为我编译为静态库,所以需要全部静态库)

make install

http://blog.csdn.net/appletreesujie/article/details/4207604

或者参考

http://hi.baidu.com/foxms/blog/item/b694ef2607cccd38c89559c4.html

 在编译时候添加samba_cv_CC_NEGATIVE_ENUM_VALUES=yes

3>

./configure --prefix=/Users/kanoutouyetao/samba-iphone  CC=arm-apple-darwin10-gcc-4.2.1 --enable-static --without-readline --with-libsmbclient --disable-cups -disable-iprintsamba_cv_CC_NEGATIVE_ENUM_VALUES=yes CPPFLAGS="-I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/gcc/arm-apple-darwin10/4.2.1/include -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/include" --host=arm-apple-darwin10 --build=x86



我编译的是samba-3.3.3的,不为何samba3.6.4的编译真机的时候没有成功!


编译仿真器上的库


1>

export LDFLAGS="-L/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/usr/lib/ -L/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/usr/lib/system/"


2>

export PATH=$PATH:/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/


3>

./configure --prefix=/Users/yetao/Desktop/samba_last/i386 CC="/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 -m32" --enable-static --without-readline --with-libsmbclient  --without-libtalloc --without-libtdb --without-libnetapi --without-libsmbsharemodes --without-libaddns--without-ldap --disable-swat--disable-cups -disable-iprint samba_cv_CC_NEGATIVE_ENUM_VALUES=yes CPPFLAGS="-I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/include -I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/usr/include" 



checking whether to enable build farm hacks... no

Using libraries:

    LIBS = -lresolv -liconv

    DNSSD_LIBS = 

    AUTH_LIBS = 

checking configure summary... configure: WARNING: cannot run when cross-compiling

configure: creating ./config.status

config.status: creating Makefile

config.status: creating script/findsmb

config.status: creating smbadduser

config.status: creating script/gen-8bit-gap.sh

config.status: creating script/installbin.sh

config.status: creating script/uninstallbin.sh

config.status: creating lib/netapi/examples/Makefile

config.status: creating pkgconfig/smbclient.pc

config.status: creating pkgconfig/wbclient.pc

config.status: creating pkgconfig/netapi.pc

config.status: creating pkgconfig/smbsharemodes.pc

config.status: creating include/config.h

config.status: executing rm-stdint.h commands

config.status: executing rm-stdbool.h commands


成功编译出i386的库,并且可以调用

当然,使用此库的时候需要添加

-lresolv -liconv两个库!在xcode lib里面添加 ,如图



编译真机上的库


1>

export LDFLAGS="-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib -L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/system"

2>


export PATH=$PATH:/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/


3>


./configure --prefix=/Users/yetao/Desktop/samba_last/armv7  CC="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" --enable-static --without-readline --with-libsmbclient --without-libtalloc --without-libtdb --without-libnetapi --without-libsmbsharemodes --without-libaddns--without-ldap --disable-swat--disable-cups -disable-iprint --enable-cross-compile samba_cv_CC_NEGATIVE_ENUM_VALUES=yes CPPFLAGS="-I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/include" --build=arm-apple-darwin10 --host=x86

你可能感兴趣的:(MAC&iPhone开发)