你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

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

2022/5/15 12:19:34

转载地址:http://hi.baidu.com/yetao19860606/item/e1b1ce3e1f5a3706cfb9fe69

首先设定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