适用于Android x86的Crosscompile Perl

时间:2017-04-21 14:02:27

标签: android linux perl gcc cross-compiling

我喜欢为Android x86模拟器交叉编译Perl。但是在运行配置时出现了PIE(位置无关的可执行文件)错误...基于thisthis教程。

规格:

  • NDK第14版
  • Perl 5.22.1。
  • 使用AOSP构建的x86 Android模拟器--Android 7.1.1

我设置了以下变量:

export ANDROID_NDK=/home/fabian/Android/Sdk/ndk-bundle
export TARGET_ARCH=x86
export ANDROID_TOOLCHAIN=/tmp/toolchain-x86
export SYSROOT=$ANDROID_TOOLCHAIN/sysroot
export TARGETDIR=/data/local/perl
export GCC=i686-linux-android-gcc
export PATH=$PATH:$ANDROID_NDK/toolchains/x86-4.9/prebuilt/linux-x86_64/bin

然后我使用以下命令构建工具链:

$ANDROID_NDK/build/tools/make-standalone-toolchain.sh --platform=android-23 --install-dir=$ANDROID_TOOLCHAIN --toolchain=x86-4.9

并得到这个(正确?)输出:

HOST_OS=linux
HOST_EXE=
HOST_ARCH=x86_64
HOST_TAG=linux-x86_64
HOST_NUM_CPUS=4
BUILD_NUM_CPUS=8
Auto-config: --arch=x86
Toolchain installed to /tmp/toolchain-x86.

然后我启动./Configure命令:

./Configure -des -Dusedevel -Dusecrosscompile -Dtargetrun=adb -Dcc=i686-linux-android-gcc -Dsysroot=$SYSROOT -Dtargetdir=$TARGETDIR -Dtargethost=emulator-5554

得到了这个输出:


    First let's make sure your kit is complete.  Checking...
    Would you like to see the instructions? [n]  
    Locating common programs...
    Checking compatibility between /bin/echo and builtin echo (if any)...
    Symbolic links are supported.
    Checking how to test for symbolic links...
    You can test for symbolic links with 'test -h'.
    Using targetarch i686-linux-android.
    Using targethost emulator-5554.
    Building host miniperl and generate_uudmap binaries
    Using targethost emulator-5554.
    Guessing targetuser root.
    Guessing targetport 22.
    Using '/home/fabian/Desktop/Testimages/perl-5.22.1/Cross/run-adb' for remote execution,
    and '/home/fabian/Desktop/Testimages/perl-5.22.1/Cross/from-scp' and '/home/fabian/Desktop/Testimages/perl-5.22.1/Cross/to-scp'
    for remote file transfer.
    Good, your tr supports [:lower:] and [:upper:] to convert case.
    Using [:upper:] and [:lower:] to convert case.
    aix_3         dragonfly       irix_4        nonstopux     stellar   
    aix_4         dynixptx        irix_5        openbsd       sunos_4_0   
    aix           dynix           irix_6_0      opus          sunos_4_1   
    altos486      epix            irix_6_1      os2           super-ux   
    amigaos       esix4           irix_6        os390         svr4   
    atheos        fps             isc_2         os400         svr5   
    aux_3         freebsd         isc           posix-bc      ti1500   
    bitrig        freemint        linux-android     powerux       ultrix_4   
    bsdos         genix           linux         qnx           umips   
    catamount     gnukfreebsd     lynxos        riscos        unicosmk   
    convexos      gnuknetbsd      midnightbsd       sco_2_3_0     unicos   
    cxux          gnu             mips          sco_2_3_1     unisysdynix   
    cygwin        greenhills      mirbsd        sco_2_3_2     utekv   
    darwin        haiku           mpc           sco_2_3_3     uwin   
    dcosx         hpux            ncr_tower     sco_2_3_4     vos   
    dec_osf       i386            netbsd        sco   
    dos_djgpp     interix         newsos4       solaris_2   
    Which of these apply, if any? [linux-android]  
    "./a.out": error: only position independent executables (PIE) are supported.
    Aborted 

    You don't have an ELF gcc.  I will use dld if possible.  If you are
    using a version of DLD earlier than 3.2.6, or don't have it at all, you
    should probably upgrade. If you are forced to use 3.2.4, you should
    uncomment a couple of lines in hints/linux.sh and restart Configure so
    that shared libraries will be disallowed.


    Disabling ndbm.  This will generate a Whoa There message in Configure.
    Read hints/linux.sh for further information.
    Operating system name? [linux-android]  
    Operating system version? [7.1.1]  
    Installation prefix to use? (~name ok) [/usr/local]  
    AFS does not seem to be running...
    What installation prefix should I use for installing files? (~name ok)
    [/usr/local]  
    Getting the current patchlevel...
    Build a threading Perl? [n]  
    Build Perl for multiplicity? [n]  
    Use which C compiler? [i686-linux-android-gcc]  
    Checking for GNU cc in disguise and/or its version number...
    "./try": error: only position independent executables (PIE) are supported.
    Aborted 
    Now, how can we feed standard input to your C preprocessor...
    Directories to use for library searches?
    [/tmp/toolchain-x86/sysroot/usr/lib/../lib /tmp/toolchain-x86/sysroot/usr/lib]  
    What is the file extension used for shared libraries? [sa]  
    Make shared library basenames unique? [n]  
    Hmm.  Based on the hints in hints/linux-android.sh, 
    the recommended value for $d_libname_unique on this machine was "define"!
        Keep the recommended value? [y]  
    Build Perl for SOCKS? [n]  
    Try to use long doubles if available? [n]  
    Checking for optional libraries...
    What libraries to use? [-lm -lc]  
    What optimizer/debugger flag should be used? [-O2]  
    Any additional cc flags?
    [-DOVR_DBL_DIG=14 --sysroot=/tmp/toolchain-x86/sysroot]  
    Let me guess what the preprocessor flags are...
    Any additional ld flags (NOT including libraries)?
    [ --sysroot=/tmp/toolchain-x86/sysroot]  
    Checking your choice of C compiler and flags for coherency...
    I've tried to compile and run the following simple program:

    #include 
    int main() { printf("Ok\n"); return(0); }

    I used the command:

        i686-linux-android-gcc -o try -O2 -DOVR_DBL_DIG=14 --sysroot=/tmp/toolchain-x86/sysroot --sysroot=/tmp/toolchain-x86/sysroot try.c -lm -lc
        /home/fabian/Desktop/Testimages/perl-5.22.1/Cross/run-adb-shell ./try
    
    and I got the following output:

    
    The program compiled OK, but exited with status 134.
    You have a problem.  Shall I abort Configure [y]  
    Ok.  Stopping Configure.

好的我必须设置标志

  

修改config.sh以启用PIE支持。将“-fPIE”附加到ccflags和   “-fPIE -pie”到ldflags。然后重新运行configure以确保这是   应用

但是perl文件夹中没有config.sh,所以我尝试了这个./Configure命令:

`./Configure -des -Dusedevel -Dusecrosscompile -Dtargetrun=adb -Dcc=i686-linux-android-gcc -Dsysroot=$SYSROOT -Dtargetdir=$TARGETDIR -Dtargethost=emulator-5554 -Dccflags='-fPIE' Dldflags='-fPIE -pie'`

但同样的问题......


    First let's make sure your kit is complete.  Checking...
    Would you like to see the instructions? [n]  
    Locating common programs...
    Checking compatibility between /bin/echo and builtin echo (if any)...
    Symbolic links are supported.
    Checking how to test for symbolic links...
    You can test for symbolic links with 'test -h'.
    Using targetarch i686-linux-android.
    Using targethost emulator-5554.
    Building host miniperl and generate_uudmap binaries
    Using targethost emulator-5554.
    Guessing targetuser root.
    Guessing targetport 22.
    Using '/home/fabian/Desktop/Testimages/perl-5.22.1/Cross/run-adb' for remote execution,
    and '/home/fabian/Desktop/Testimages/perl-5.22.1/Cross/from-scp' and '/home/fabian/Desktop/Testimages/perl-5.22.1/Cross/to-scp'
    for remote file transfer.
    Good, your tr supports [:lower:] and [:upper:] to convert case.
    Using [:upper:] and [:lower:] to convert case.
    aix_3         dragonfly       irix_4        nonstopux     stellar   
    aix_4         dynixptx        irix_5        openbsd       sunos_4_0   
    aix           dynix           irix_6_0      opus          sunos_4_1   
    altos486      epix            irix_6_1      os2           super-ux   
    amigaos       esix4           irix_6        os390         svr4   
    atheos        fps             isc_2         os400         svr5   
    aux_3         freebsd         isc           posix-bc      ti1500   
    bitrig        freemint        linux-android     powerux       ultrix_4   
    bsdos         genix           linux         qnx           umips   
    catamount     gnukfreebsd     lynxos        riscos        unicosmk   
    convexos      gnuknetbsd      midnightbsd       sco_2_3_0     unicos   
    cxux          gnu             mips          sco_2_3_1     unisysdynix   
    cygwin        greenhills      mirbsd        sco_2_3_2     utekv   
    darwin        haiku           mpc           sco_2_3_3     uwin   
    dcosx         hpux            ncr_tower     sco_2_3_4     vos   
    dec_osf       i386            netbsd        sco   
    dos_djgpp     interix         newsos4       solaris_2   
    Which of these apply, if any? [linux-android]  
    "./a.out": error: only position independent executables (PIE) are supported.
    Aborted 

    You don't have an ELF gcc.  I will use dld if possible.  If you are
    using a version of DLD earlier than 3.2.6, or don't have it at all, you
    should probably upgrade. If you are forced to use 3.2.4, you should
    uncomment a couple of lines in hints/linux.sh and restart Configure so
    that shared libraries will be disallowed.


    Disabling ndbm.  This will generate a Whoa There message in Configure.
    Read hints/linux.sh for further information.
    Operating system name? [linux-android]  
    Operating system version? [7.1.1]  
    Installation prefix to use? (~name ok) [/usr/local]  
    AFS does not seem to be running...
    What installation prefix should I use for installing files? (~name ok)
    [/usr/local]  
    Getting the current patchlevel...
    Build a threading Perl? [n]  
    Build Perl for multiplicity? [n]  
    Use which C compiler? [i686-linux-android-gcc]  
    Checking for GNU cc in disguise and/or its version number...
    "./try": error: only position independent executables (PIE) are supported.
    Aborted 
    Now, how can we feed standard input to your C preprocessor...
    Directories to use for library searches?
    [/tmp/toolchain-x86/sysroot/usr/lib/../lib /tmp/toolchain-x86/sysroot/usr/lib]  
    What is the file extension used for shared libraries? [sa]  
    Make shared library basenames unique? [n]  
    Hmm.  Based on the hints in hints/linux-android.sh, 
    the recommended value for $d_libname_unique on this machine was "define"!
        Keep the recommended value? [y]  
    Build Perl for SOCKS? [n]  
    Try to use long doubles if available? [n]  
    Checking for optional libraries...
    What libraries to use? [-lm -lc]  
    What optimizer/debugger flag should be used? [-O2]  
    Any additional cc flags?
    [-DOVR_DBL_DIG=14 -fPIE --sysroot=/tmp/toolchain-x86/sysroot]  
    Let me guess what the preprocessor flags are...
    Any additional ld flags (NOT including libraries)?
    [ --sysroot=/tmp/toolchain-x86/sysroot]  
    Checking your choice of C compiler and flags for coherency...
    I've tried to compile and run the following simple program:

    #include 
    int main() { printf("Ok\n"); return(0); }

    I used the command:

        i686-linux-android-gcc -o try -O2 -DOVR_DBL_DIG=14 -fPIE --sysroot=/tmp/toolchain-x86/sysroot --sysroot=/tmp/toolchain-x86/sysroot try.c -lm -lc
        /home/fabian/Desktop/Testimages/perl-5.22.1/Cross/run-adb-shell ./try

    and I got the following output:

    "./try": error: only position independent executables (PIE) are supported.
    Aborted 
    The program compiled OK, but exited with status 134.
    You have a problem.  Shall I abort Configure [y]  
    Ok.  Stopping Configure.

但是现在ccflag设置了你在最后几行中看到的......

我错过了什么吗?

0 个答案:

没有答案