Cross compiling PCRE with CodeSourcery toolchain?

1.4k views Asked by At

I am trying to compile PCRE with CodeSourcery here is my configure script

#!/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};

now it is successfully compiled but when i tried to execute that binary on android i get:

  ./pcregrep: not found

also having similar issue when cross-comping curl, openssl but when i run a test code

#include <stdio.h>

int main(){

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

and compile with following option

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

it works

2

There are 2 answers

0
vinay hunachyal On

Its a mismatch between libc of code-sourcery tool-chain and libc which is in target rootfs. libc in the host cross-compiler and deployed on the device rootfs are different

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

it works `

This works since you compiling statically so there is no need to copy libc to target here.

But pcre you built dynamically .check file ./pcregrep if its dynamic linked then

one easiest way compile statically as hello eg. and run on your target.

otherwise copy libc from tool chain to target and export it then it will work

3
ams On

You're trying to use a Linux compiler with Android. It's not completely broken because Android is Linux, but Android doesn't come with the same set of libraries, as standard.

It's probably possible to install the Linux libraries (from the appropriate CodeSourcery libc directory), but that's a tricky process because the Android files will already be in the standard locations so they'll have to be installed to one side, somehow, and if you don't know what you're doing it'll get into a horrible mess.

The best solution is probably to use entirely static linking. That said, you might still find that libcurl is unhappy because, even statically linked, it requires that it can dlopen the DNS library of the host system, and I don't know how Android likes to do that.

I would suggest you try to get hold of a purpose-built Android toolchain (I believe Linaro do one) that is designed to use Android's "Bionic" C library, rather than GNU/Linux's "Glibc".