2010年9月17日 星期五

cross compile for samba

ref: http://hi.baidu.com/jiaolingqi/blog/item/640fa777dd21ba12b051b9db.html

cross compile samba(mipsel-linux)

2009/06/16 14:09
今天完成了交叉編譯samba的學習。將samba移植到mipsel-linux平台上。相關工作流程如下。

一:簡介
製作mipsel-linux交叉編譯工具鏈;
使用samba-3.3.3.tar.gz源代碼;

二:流程
1、在/etc/profile中設置mipsel-linux交叉編譯工具路徑,執行source指令使之生效;
或者在當前終端標籤頁中使用export PATH=${bin directory of mipsel-linux}:$PATH

2、解壓samba到設定之目錄;

3、configure腳本build.sh
***********************************************

#!/bin/bash

export CFLAGS='-O3 -w -isystem /Cross/target/local/mipsel-linux/include'
export CPPFLAGS='-O3 -w -isystem /Cross/target/local/mipsel-linux/include'
export PATH=/Cross/target/local/bin:$PATH
export LD_LIBRARY_PATH=/Cross/target/local/bin/mipsel-linux-gcc
export CC=/Cross/target/local/bin/mipsel-linux-gcc
export CPP=/Cross/target/local/bin/mipsel-linux-cpp

./configure --build=i686-linux --host=mipsel-linux --target=mipsel-linux \
--includedir=/Cross/target/local/mipsel-linux/include \
--oldincludedir=/Cross/target/local/mipsel-linux/include \
--disable-largefile \
--enable-swat=no \
--enable-cups=no \
--enable-iprint=no \
--enable-pie=no \
--enable-fam=no \
--enable-static=yes \
--enable-shared-libs=no \
--enable-dnssd=no \
--with-ldap=no \
--with-ads=no \
--with-cifsmount=no \
--with-utmp=no \
--with-libtalloc=no \
--with-libtdb=no \
--with-libnetapi=no \
--with-libaddns=no \
--with-libsmbclient=no \
--with-libsmbsharemodes=no \
--with-acl-support=no \
--with-sendfile-support=no \
--with-winbind=no \
--with-static-modules=nmbd,smbd,smbclient,smbpasswd \
--bindir=$MQARMDIR/bin \
--sbindir=$MQARMDIR/bin \
--localstatedir=$MQUSERDIR/samba/var \
--libdir=$MQARMDIR/lib \
--with-privatedir=$MQUSERDIR/samba/private \
--with-rootsbindir=$MQARMDIR/bin \
--with-lockdir=$MQUSERDIR/samba/var/locks \
--with-configdir=$MQUSERDIR/samba \
--with-logfilebase=$MQUSERDIR/samba/var \
--with-piddir=$MQUSERDIR/samba/var \
--cache-file=mipsel-linux.cache
***********************************************

執行該編譯腳本。在編譯過程中會出現一些問題,現描述如下:
3.1 error: cannot run test program while cross compiling錯誤
checking that the C compiler understands negative enum values... configure: error: in `/root/samba-3.3.3/source':
configure: error: cannot run test program while cross compiling

原因:
查找「negative enum values」關鍵字,就可以找到問題發生的地方。
通常我們configure的時候使用./configure --build=i686-linux --host=$ARCH-linux --target=$ARCH-linux的形式,但是在configure中有很多的測試程序是不能在HOST上運行的configure不能為交叉編譯檢查samba_cv_CC_NEGATIVE_ENUM_VALUESconfigure無法在目標機上運行測試程序,自然無法檢查,只好手工指定。

解決方法:
#echo samba_cv_CC_NEGATIVE_ENUM_VALUES=yes>mipsel-linux.cache
然後在build.sh腳本中的最後一行添加「--cache-file=mipsel-linux.cache」
如果後面還遇到類似的問題,則之需要找到相關的地方,並將指定的值追加到mipsel-linux.cache文件中。

3.2 configure: error: cannot run test program while cross compiling錯誤
configure: error: in `/root/samba-3.3.3/source':
configure: error: cannot run test program while cross compiling
See `config.log' for more details.

原因:這個錯誤是由於configure對交叉編譯支持的問題造成的,通過在configure文件中查找,您可以看到原文件中該部分的內容為:
******************************************

{ $as_echo "$as_me:$LINENO: checking for replacing readdir using getdirentries()" >&5
$as_echo_n "checking for replacing readdir using getdirentries()... " >&6; }
if test "${libreplace_cv_READDIR_GETDIRENTRIES+set}" = set; then
$as_echo_n "(cached) " >&6
else

if test "$cross_compiling" = yes; then
{ { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
See \`config.log' for more details." >&5
$as_echo "$as_me: error: cannot run test program while cross compiling
See \`config.log' for more details." >&2;}
{ (exit 1); exit 1; }; }; }
else
cat >conftest.$ac_ext <<_aceof>&5
$as_echo_n "checking for replacing readdir using getdirentries()... " >&6; }
if test "${libreplace_cv_READDIR_GETDIRENTRIES+set}" = set; then
$as_echo_n "(cached) " >&6
else

if test "$cross_compiling" = yes; then
{ { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
See \`config.log' for more details." >&5
$as_echo "$as_me: error: cannot run test program while cross compiling
See \`config.log' for more details." >&2;}
}; } #新增該行
#註銷該行 { (exit 1); exit 1; }; }; }
else
cat >conftest.$ac_ext <<_aceof style="color: rgb(0, 0, 0);">error: cannot run test program while cross compiling」查找configure文件,將其中相關代碼都修改過來,即可以解決該問題。

3.3 頭文件錯誤
編譯過程中會出現找不到頭文件的錯誤,拷貝/usr/include/linux/dqblk_xfs.h文件到mipsel-linux交叉編譯工具鏈的linux/include目錄中;
cp /usr/include/linux/dqblk_xfs.h /Cross/target/local/mipsel-linux/include/linux

3.4 庫文件連接錯誤:找不到-lcups
拷貝交叉編譯的cups相關庫到mipsel-linux交叉編譯工具鏈的lib目錄中
cp /crosstool/test/cups/mips/cups-1.3.9/cups/libcups.a /Cross/target/local/mipsel-linux/lib
cp /crosstool/test/cups/mips/cups-1.3.9/cups/libcups.so* /Cross/target/local/mipsel-linux/lib

以上目錄需要自己指定您機器上的目錄,以上只是本機的目錄。

4、make
執行make指令。
原帖地址:http://chujb.spaces.live.com/Blog/cns!21F0BD7DB657E864!204.entry

沒有留言:

張貼留言

使用 google 的 reCAPTCHA 驗證碼, 總算可以輕鬆留言了。

我實在受不了 spam 了, 又不想讓大家的眼睛花掉, 只好放棄匿名留言。這是沒辦法中的辦法了。留言的朋友需要有 google 帳號。