LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 4314|回复: 16

关于arm-linux交叉编译的问题

[复制链接]
发表于 2007-4-20 10:53:09 | 显示全部楼层 |阅读模式
使用arm-linux交叉编译 samba 服务,make过程中报N多头文件不存在,无法编译通过。
别人建议在configure时将相关服务关闭,但我有一个疑惑是我如何确定哪些服务与那些缺少的头文件相关,我觉得该种方法可行性比较低。也尝试过congfigure中将所有选项都取消,直接导致编译失败。
谁有比较好的可行方案,敬请赐教,谢谢!
发表于 2007-4-20 11:18:09 | 显示全部楼层
如果楼主不是这么笼统的描述,而是把错误信息帖出来,也许会有人提供进一步的帮助
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-4-20 11:33:50 | 显示全部楼层
由于对这个事情的概念还是比较模糊的,也很难表述得非常清楚。个人感觉可能产生问题的环节过多,已经不知该从何谈起了……十分郁闷
大概的流程是创建交叉编译环境
binutils-2.14
gcc-3.3
glibc-2.2.5
linux-2.4.21
gdb-5.3
现已将交叉编译器安装好了,目录是/usr/local/arm ./bin已经加入环境变量
然后下载了 samba 2.0.7,按照说明,进入source/下运行./configure --进行配置,生成了一个Makefile文件。最后执行make 接着就连续报缺少头文件了 比如acl.h……
回复 支持 反对

使用道具 举报

发表于 2007-4-20 12:34:48 | 显示全部楼层
假如是作交叉编译的话,首先要把所有需要的包安装到你的交叉编译环境中(而不是你的 PC 环境),而在交叉编译某个包的的时候,一般要指定 host,target 之类的,要指定 prefix,要指定所使用的编译器。

楼主如果不知道该提供哪些信息,就把你执行的命令原样帖上来就好了。对于出现错误的命令,就把错误的部分帖出来
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-4-20 13:48:10 | 显示全部楼层
我的交叉编译环境是用别人做的build.sh 直接运行的
#!/bin/sh
#******************************************************************************
#
# build.sh - Shell script to build the arm-linux tool chain.
#
# Copyright (c) 2004 Cirrus Logic, Inc.
#
#******************************************************************************

#
# INSTDIR is the path where the tool chain will be installed.
#
INSTDIR=/usr/local/arm/3.3

#
# GNU is the location from which GNU source tarballs are fetched if they do not
# exist.
#
GNU=ftp://ftp.gnu.org

#
# KERNEL is the location from which the Linux source tarball is fetched if it
# does not exist.
#
KERNEL=ftp://ftp.kernel.org/pub/linux/kernel/v2.4

#
# ARMLINUX is the location from which the ARM Linux patch is fetched if it does
# not exist.
#
ARMLINUX=ftp://ftp.arm.linux.org.uk/pub/armlinux/source/kernel-patches/v2.4

#******************************************************************************
#
# Setup the execution environment for building the tool chain.
#
#******************************************************************************

#
# HEADERS is the path where the Linux kernel headers are found.
#
HEADERS=`pwd`/linux-2.4.21/include

#
# DESTDIR is the path where the tool chain will be placed as part of the build
# process.  The tool chain must then be copied (manually) to ${INSTDIR} in
# order to run.
#
DESTDIR=`pwd`/install

#
# Add the installed tool chain to the search path.  This is required so that
# the gcc and glibc builds can find the target assembler and linker.
#
PATH=${DESTDIR}${INSTDIR}/binPATH

#
# Redirect stdout and stderr to a file, and make descriptor 3 be stdout.  This
# will capture all output into the log file, and allow informational messages
# to be displayed during the build via "echo {blah} >&3".
#
exec 3>&1 1>build.log 2>&1

#******************************************************************************
#
# Bail out because of an error.
#
#******************************************************************************
failure ()
{
    #
    # Indicate that an error occurred.
    #
    echo Build step failed! >&3

    #
    # Exit with a failure return code.
    #
    exit 1
}

#******************************************************************************
#
# Execute a command with error checking.  Note that when using this, if a piped
# command is used, the '|' must be escaped with '\' when calling try (i.e.
# "try ls \| less").
#
#******************************************************************************
try ()
{
    #
    # Execute the command and fail if it does not return zero.
    #
    eval ${*} || failure
}

#******************************************************************************
#
# Fetches a tarball with wget if it does not already exist in the local cache.
#
#******************************************************************************
fetch_tarball ()
{
    #
    # See if the tarball exists.
    #
    if [ ! -f ${2} ]
    then
        #
        # Fetch the tarball since it does not exist.
        #
        echo Fetching ${2}... >&3
        try wget ${1}/${2}
    fi
}

#******************************************************************************
#
# Build binutils.  This provides arm-linux-as, arm-linux-ar, arm-linux-ld, etc.
#
#******************************************************************************

#
# Get the binutils tarball.
#
fetch_tarball ${GNU}/gnu/binutils binutils-2.14.tar.bz2

#
# Unpack the binutils tarball.
#
echo Unpacking binutils... >&3
try tar -xjf binutils-2.14.tar.bz2

#
# Patch a few things in the binutils source.
#
try bzcat binutils-2.14.patch.bz2 2\>\&1 \| patch -p1 -E -d binutils-2.14

#
# Create a build directory and switch into it.
#
try mkdir binutils-2.14/build
try pushd binutils-2.14/build

#
# Configure binutils.
#
echo Configuring binutils... >&3
try CFLAGS=-O2                       \
    CXXFLAGS=-O2                     \
    ../configure --target=arm-linux  \
                 --prefix=${INSTDIR}

#
# Build binutils.
#
echo Building binutils... >&3
try make

#
# Install binutils.
#
echo Installing binutils... >&3
try make DESTDIR=${DESTDIR} install

#
# Remove the binutils source and objects.
#
try popd
try rm -rf binutils-2.14

#******************************************************************************
#
# Build gcc (stage 1).  This provides just a basic C compiler that is used to
# build glibc.
#
#******************************************************************************

#
# Get the gcc tarball.
#
fetch_tarball ${GNU}/gnu/gcc/gcc-3.3 gcc-3.3.tar.bz2

#
# Unpack the gcc tarball.
#
echo Unpacking gcc... >&3
try tar -xjf gcc-3.3.tar.bz2

#
# Patch a few things in the gcc source.
#
try bzcat gcc-3.3.patch.bz2 2\>\&1 \| patch -p1 -E -d gcc-3.3

#
# Create a build directory and switch into it.
#
try mkdir gcc-3.3/build
try pushd gcc-3.3/build

#
# Configure gcc.
#
echo Configuring gcc \(stage 1\)... >&3
try CFLAGS=-O2                             \
    CXXFLAGS=-O2                           \
    DESTDIR=${DESTDIR}                     \
    ../configure --target=arm-linux        \
                 --prefix=${INSTDIR}       \
                 --with-headers=${HEADERS} \
                 --disable-shared          \
                 --disable-threads         \
                 --disable-debug           \
                 --enable-languages="c"

#
# Build gcc.
#
echo Building gcc \(stage 1\)... >&3
try make DESTDIR=${DESTDIR} build_tooldir=${DESTDIR}${INSTDIR}/arm-linux

#
# Install gcc.
#
echo Installing gcc \(stage 1\)... >&3
try make DESTDIR=${DESTDIR} install

#
# Remove the gcc objects, leaving the source for use a bit later.
#
try popd
try rm -rf gcc-3.3/build

#******************************************************************************
#
# Configure the kernel as necessary.  The kernel needs to be configured and the
# dependencies computed in order to properly build the tool chain, but the
# basic C compiler is needed to configure and compute the dependencies!
# The kernel is only configured if it has not been yet, and the dependencies
# are only computed if they have not been yet.  A standard kernel configuration
# is used since the specific configuration to be used is not important to the
# tool chain.
#
#******************************************************************************

#
# Check for the Linux source directory.
#
if [ ! -d linux-2.4.21 ]
then
    #
    # Get the Linux tarball.
    #
    fetch_tarball ${KERNEL} linux-2.4.21.tar.bz2

    #
    # Get the ARM Linux patch.
    #
    fetch_tarball ${ARMLINUX} patch-2.4.21-rmk1.bz2

    #
    # Extract the Linux tarball.
    #
    echo Unpacking linux... >&3
    try tar -xjf linux-2.4.21.tar.bz2

    #
    # Patch the linux source.
    #
    echo Patching linux... >&3
    try bzcat patch-2.4.21-rmk1.bz2 2\>\&1 \| patch -p1 -E -d linux-2.4.21

    #
    # Fix the ARCH and CROSS_COMPILE lines in the linux Makefile.
    #
    try perl -i -p -e \'s/^ARCH.*/ARCH := arm/\' linux-2.4.21/Makefile
    try perl -i -p -e \'s/^CROSS_COMPILE.*/CROSS_COMPILE = arm-linux-/\' \
             linux-2.4.21/Makefile
fi

#
# See if the kernel needs to be configured.
#
if [ ! -f linux-2.4.21/.config ]
then
    echo Configuring linux... >&3
    try cp linux.config linux-2.4.21/.config
    try make -C linux-2.4.21 oldconfig
fi

#
# See if the kernel dependencies need to be created.
#
if [ ! -f linux-2.4.21/.depend ]
then
    echo Creating linux dependencies... >&3
    try make -C linux-2.4.21 dep
fi

#******************************************************************************
#
# Build glibc.  This provides the C and associated support libraries.
#
#******************************************************************************

#
# Get the glibc tarball.
#
fetch_tarball ${GNU}/gnu/glibc glibc-2.2.5.tar.gz

#
# Get the glibc-linuxthreads tarball.
#
fetch_tarball ${GNU}/gnu/glibc glibc-linuxthreads-2.2.5.tar.gz

#
# Unpack the glibc tarballs.
#
echo Unpacking glibc... >&3
try tar -xzf glibc-2.2.5.tar.gz
try tar -C glibc-2.2.5 -xzf glibc-linuxthreads-2.2.5.tar.gz

#
# Patch a few things in the glibc source.
#
try bzcat glibc-2.2.5.patch.bz2 2\>\&1 \| patch -p1 -E -d glibc-2.2.5

#
# Create a build directory and switch into it.
#
try mkdir glibc-2.2.5/build
try pushd glibc-2.2.5/build

#
# Configure glibc.
#
echo Configuring glibc... >&3
try CFLAGS=-O2                             \
    CXXFLAGS=-O2                           \
    ../configure arm-linux                 \
                 --build=i686-pc-linux-gnu \
                 --with-headers=${HEADERS} \
                 --enable-add-ons          \
                 --enable-shared           \
                 --prefix=${INSTDIR}

#
# Build glibc.
#
echo Building glibc... >&3
try make

#
# Install glibc.
#
echo Installing glibc... >&3
try make install_root=${DESTDIR} install

#
# Fix the symlinks in the arm-linux/lib install directory.
#
try pushd ${DESTDIR}${INSTDIR}/arm-linux/lib
try ln -sf ../../lib/* .
try popd

#
# Remove the glibc source and objects.
#
try popd
try rm -rf glibc-2.2.5

#******************************************************************************
#
# Build gcc (stage 2).  This provides a full C and C++ compiler.
#
#******************************************************************************

#
# Remove the system includes from the install directory.  This will get
# re-populated when gcc is re-configured.
#
try rm -rf ${DESTDIR}${INSTDIR}/arm-linux/sys-include

#
# Patch a few things in the gcc source.
#
try perl -i -p -e \'s/-Dinhibit_libc//g\' gcc-3.3/gcc/config/arm/t-linux

#
# Create a build directory and switch into it.
#
try mkdir gcc-3.3/build
try pushd gcc-3.3/build

#
# Configure gcc.
#
echo Configuring gcc \(stage 2\)... >&3
try CFLAGS=-O2                              \
    CXXFLAGS=-O2                            \
    DESTDIR=${DESTDIR}                      \
    ../configure --target=arm-linux         \
                 --prefix=${INSTDIR}        \
                 --with-headers=${HEADERS}  \
                 --disable-debug            \
                 --enable-languages="c,c++"

#
# Temporarily modify the libc.so ld script so that the paths are "correct".
#
try cp ${DESTDIR}${INSTDIR}/lib/libc.so ${DESTDIR}${INSTDIR}/lib/libc.so.orig
try perl -i -p -e \"s,${INSTDIR},${DESTDIR}${INSTDIR},g\" \
         ${DESTDIR}${INSTDIR}/lib/libc.so

#
# Build gcc.
#
echo Building gcc \(stage 2\)... >&3
try make DESTDIR=${DESTDIR} build_tooldir=${DESTDIR}${INSTDIR}/arm-linux

#
# Install gcc.
#
echo Installing gcc \(stage 2\)... >&3
try make DESTDIR=${DESTDIR} install

#
# Restore the correct libc.so ld script.
#
try cp ${DESTDIR}${INSTDIR}/lib/libc.so.orig ${DESTDIR}${INSTDIR}/lib/libc.so
try rm -f ${DESTDIR}${INSTDIR}/lib/libc.so.orig

#
# Remove the gcc source and objects.
#
try popd
try rm -rf gcc-3.3

#******************************************************************************
#
# Build gdb.  This provides a debugger that can connect to the gdbserver on the
# target system.
#
#******************************************************************************

#
# Get the gdb tarball.
#
fetch_tarball ${GNU}/gnu/gdb gdb-5.3.tar.gz

#
# Unpack the gdb tarball.
#
echo Unpacking gdb... >&3
try tar -xzf gdb-5.3.tar.gz

#
# Patch a few things in the gdb source.
#
try bzcat gdb-5.3.patch.bz2 2\>\&1 \| patch -p1 -E -d gdb-5.3

#
# Create a build directory and switch into it.
#
try mkdir gdb-5.3/build
try pushd gdb-5.3/build

#
# Configure gdb.
#
echo Configuring gdb... >&3
try CFLAGS=-O2                       \
    CXXFLAGS=-O2                     \
    ../configure --target=arm-linux  \
                 --prefix=${INSTDIR} \
                 --disable-sim

#
# Build gdb.
#
echo Building gdb... >&3
try make

#
# Install gdb.
#
echo Installing gdb... >&3
try make DESTDIR=${DESTDIR} install

#
# Remove the gdb source and objects.
#
try popd
try rm -rf gdb-5.3

#******************************************************************************
#
# Strip the executables in the install directory.
#
#******************************************************************************
for i in addr2line ar as c++ c++filt cpp g++ gcc gcov gdb ld \
         nm objcopy objdump ranlib readelf size strings strip
do
    try strip ${DESTDIR}${INSTDIR}/bin/arm-linux-${i}
done
for i in gencat getconf getent iconv locale \
         localedef pcprofiledump rpcgen sprof
do
    try arm-linux-strip ${DESTDIR}${INSTDIR}/bin/${i}
done
for i in iconvconfig ldconfig nscd nscd_nischeck rpcinfo sln zic zdump
do
    try arm-linux-strip ${DESTDIR}${INSTDIR}/sbin/${i}
done
try arm-linux-strip ${DESTDIR}${INSTDIR}/libexec/pt_chown
try strip ${DESTDIR}${INSTDIR}/arm-linux/bin/*
for i in cc1 cc1plus collect2
do
    try strip ${DESTDIR}${INSTDIR}/lib/gcc-lib/arm-linux/3.3/${i}
done

#******************************************************************************
#
# Success.
#
#******************************************************************************
exit 0
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-4-20 13:50:18 | 显示全部楼层
我把arm-linux-gcc所在目录加入了环境变量
然后 我自己编写了一个简单的程序 1.c 试验了一下编译
#include <stdio.h>
main(){
printf("jsfjlsdjf");
}
使用arm-linux-gcc -o 1.o 1.c 成功编译生成1.o
回复 支持 反对

使用道具 举报

发表于 2007-4-20 13:59:05 | 显示全部楼层
楼主是在编译 samba 的时候出错的吗?那么把编译 samba 的步骤帖出来
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-4-20 14:01:10 | 显示全部楼层
下载samba2.0.7 将其放在/root下
首先尝试在本机linux环境下编译,具体步骤为
$cd /root/sam2.0.7/source
$./configure --prefix=/usr/local/samba
    完成后生成了Makefile
$make
成功完成编译

然后我将 Makefile下的CC=gcc 改成了CC=arm-linux-gcc 使用 交叉编译器进行编译
运行make 以后报 找不到 sys/acl.h 和 cups/printing
我对比了本机Linux和 交叉编译的include文件 发现,确实缺少这两个文件,至此就束手无策了
回复 支持 反对

使用道具 举报

发表于 2007-4-20 14:33:22 | 显示全部楼层
这样是不对的。configure 要针对编译环境做很多配置的,这种方法是不可行的。楼主试试这样做

  1. CC=arm-linux-gcc ./configure --prefix=/usr/local/arm --target=arm-linux && make
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-4-20 14:47:54 | 显示全部楼层
还是错误 报错刷屏速度极快……

……
include/proto.h:2142:error:parse error before '*' token
include/proto.h:2142:error:parse error before '*' token
include/proto.h:2142:error:parse error before '*' token
include/proto.h:2142:error:parse error before  "SRV_Q_NET_CONN_ENUM"
……
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表