【问题标题】:Cross compiling PCRE with CodeSourcery toolchain?使用 CodeSourcery 工具链交叉编译 PCRE?
【发布时间】:2014-03-09 08:52:36
【问题描述】:

我正在尝试用CodeSourcery 编译PCRE 这是我的配置脚本

#!/bin/bash

PROJECT_BASE=$(pwd);
PROJECT_REPOSITORY=$PROJECT_BASE/download
INSTALL_PREFIX=$PROJECT_BASE/compiled/armv5te

mkdir -p $INSTALL_PREFIX && mkdir -p $PROJECT_BASE/download && mkdir -p $PROJECT_BASE/build

export TOOL_PREFIX=${HOME}/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux
SYSROOT=$HOME/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/arm-none-linux-gnueabi/libc

export CC="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-gcc --sysroot=$SYSROOT"
export CXX="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-g++ --sysroot=$SYSROOT"

#CC="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-gcc"
#CXX="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-g++"

export AR="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-ar"
export RANLIB="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-ranlib"
export LD="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-ld"
export STRIP="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-strip"
export NM="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-nm"
export CCLD=$LD
export CHOST=arm-none-linux-gnueabi


PARENT_DIR=$(pwd);

cd $PROJECT_BASE/build && tar -xzvf $PROJECT_REPOSITORY/pcre-8.34.tar.gz && cd ./pcre-8.34

#LDFLAGS_DEP="-lc"

#CPPFLAGS="-I${INSTALL_PREFIX}/include"


# CFLAGS="-march=armv5t -marm -mlittle-endian -mglibc -static -I${INSTALL_PREFIX}/include"
LDFLAGS="-L${INSTALL_PREFIX}/lib"
./configure --prefix=$INSTALL_PREFIX/pcre --with-sysroot --target=arm-none-linux-gnueabi --host=x86_64 && make && make install;
   cd -;

   cd ${PARENT_DIR};

现在它已成功编译,但是当我尝试在 android 上执行该二进制文件时,我得到:

  ./pcregrep: not found

在交叉编译 curl、openssl 时也有类似的问题,但是当我运行测试代码时

#include <stdio.h>

int main(){

   printf("Hell ya it works");
   return 0;
}

并使用以下选项进行编译

arm-none-linux-gnueabi-gcc hello.c -static -o hello.c

有效

【问题讨论】:

    标签: gcc arm cross-compiling pcre codesourcery


    【解决方案1】:

    您正在尝试在 Android 上使用 Linux 编译器。它并没有完全坏掉,因为 Android Linux,但 Android 并没有按照标准提供相同的库集。

    可能可以安装 Linux 库(从相应的 CodeSourcery libc 目录),但这是一个棘手的过程,因为 Android 文件已经位于标准位置,因此必须以某种方式将它们安装到一侧,如果你不知道自己在做什么,就会陷入可怕的混乱中。

    最好的解决方案可能是使用完全静态的链接。也就是说,你可能仍然会发现 libcurl 不满意,因为即使是静态链接,它也要求它可以dlopen 主机系统的 DNS 库,我不知道 Android 喜欢这样做。

    我建议您尝试使用专门构建的 Android 工具链(我相信 Linaro 会这样做),该工具链旨在使用 Android 的“仿生”C 库,而不是 GNU/Linux 的“Glibc”。

    【讨论】:

    • 奇怪,添加LDFALSG="-lc" 生成的二进制文件已成功编译,但在LinaroNDK 工具链的情况下,我什至不需要使用那些我认为CodeSourcery 无法使用的标志检测--sysroot
    • 我认为 CodeSourcery 编译器可能具有 --sysroot 的内置值,它可能会覆盖您的值。您可以通过-v 进行确认。一般来说,将为 Glibc 构建的编译器指向另一个 libc(例如 Bionic)是不安全的。它将以微妙的方式错误配置。
    • 我认为你可能会更好地使用这个工具链:releases.linaro.org/14.02/components/android/toolchain/4.8
    【解决方案2】:

    代码源工具链的 libc 与目标 rootfs 中的 libc 不匹配。 宿主机交叉编译器中的libc和部署在设备上的rootfs不同

    arm-none-linux-gnueabi-gcc hello.c -static -o hello.c

    它的工作原理`

    这是因为你是静态编译的,所以不需要将 libc 复制到这里的目标。

    但是pcre你是动态构建的。check file ./pcregrep如果它是动态链接的,那么

    一种最简单的方法静态编译为 hello 例如。并在你的目标上运行。

    否则将libc从工具链复制到目标并导出它就可以工作了

    【讨论】:

      猜你喜欢
      • 2012-07-10
      • 1970-01-01
      • 1970-01-01
      • 2016-03-16
      • 1970-01-01
      • 1970-01-01
      • 2013-12-09
      • 1970-01-01
      • 2011-04-17
      相关资源
      最近更新 更多