cyd has asked for the wisdom of the Perl Monks concerning the following question:

I am building perl 5.20 on an android device within the KBOX app (details available if necessary). Thanks to its broken linker, I need to link libperl.so with every extension that uses symbols from it. I am new to the perl configure/build process...how would I go about doing this?


UPDATE: Running the self-created build script suggested by an AnonymousMonk installed perl instead of stopping when PL_RE.so wouldn't load (see error posted below). The resulting install allowed me to successfully build autoconf and automake on device, which was the end goal of building perl.

FYI, I'd like to eventually learn perl, and plan on using the interpreter I've built on my Android tablet to do so, so I'd still like to figure out why the DynaLoader.pm won't load PL_re.so...and if it is just that shared module that won't load or are all shared modules broken

  • Comment on How To Link -lperl to Extensions During Build

Replies are listed 'Best First'.
Re: How To Link -lperl to Extensions During Build
by Corion (Patriarch) on May 09, 2015 at 21:55 UTC

    If you really, really want to go that way, I think the -Dldflags or -Aldflags (for -Append) options to ./Configure are the way. But are you sure you don't want to use the cctools? They come with a shell window and make, gcc and all the shell utilities and at least I didn't need to jump through too many hoops when compiling Perl for Android.

    The configure command I use to compile Perl 5.21.11 on Android is:

    sh ./Configure -Dprefix=/storage/sdcard0/perl -des -Dusedevel -Dprefix=/data/local/perl-5.21.11/ -Dsysroot=/data/data/com.pdaxrom.cctools/root/cctools -Alibpth=/system/lib /vendor/lib -Dman1dir=none -Dman3dir=none -Dsite1man=none -Dsite3man=none -Dvendorman1=none -Dvendorman3=none -DNO_LOCALE

    Also you might want to take a look at App::staticperl, which will try to compile a perl with all libraries linked statically into it.

      KBOX is a shell environment that emulates a Linux filesystem...make, gcc and a ton of other utilites are included.

      Its one quirk is that it only supports dynamic linking to libc...that plus Android's broken linker means any ext that uses symbols from libperl.so needs to be linked to it.

      Will using -Aldflags propagate down to the part of the build where extensions are compiled?

      Additionally, -Aldflags doesn't seem to work...

        I think you will have to show some of your output how -Aldflags fails, and maybe also how installing modules fails after you've compiled your Perl.

      Hopefully this post will show up in the thread this time...having a bit of difficulty posting via tablet

      Here's how the extensions build fails. WARNING: lengthy output follows

      make[1]: Leaving directory `/bld/perl/perl-5.20.2/dist/threads-shared' LD_LIBRARY_PATH=/bld/perl/perl\-5.20.2:/data/data/jackpal.androidterm/ +kbox2/lib ./perl -Ilib -f pod/buildtoc -q Can't load 'lib/5.20.2/armv7l-linux-android/auto/re/PL_re.so' for modu +le re: dlopen failed: cannot locate symbol "Perl_bytes_to_utf8" refer +enced by "PL_re.so"... at lib/5.20.2/armv7l-linux-android/DynaLoader. +pm line 218. at lib/5.20.2/Text/Wrap.pm line 58. Compilation failed in require at lib/5.20.2/Text/Wrap.pm line 58. BEGIN failed--compilation aborted at lib/5.20.2/Text/Wrap.pm line 58. Compilation failed in require at pod/buildtoc line 7. BEGIN failed--compilation aborted at pod/buildtoc line 7. make: *** [pod/perltoc.pod] Error 2

      Here's how the build fails with -Aldflags

      Use which C compiler? [gcc --sysroot=/usr/gcc-4.9.2/sysroot] /usr/gcc-4.9.2/bin/ld: cannot find -lperl collect2: error: ld returned 1 exit status Uh-oh, the C compiler 'gcc --sysroot=/usr/gcc-4.9.2/sysroot' doesn't s +eem to be working. /usr/gcc-4.9.2/bin/ld: cannot find -lperl collect2: error: ld returned 1 exit status Uh-oh, the C compiler 'gcc --sysroot=/usr/gcc-4.9.2/sysroot' doesn't s +eem to be working. You need to find a working C compiler. Either (purchase and) install the C compiler supplied by your OS vendo +r, or for a free C compiler try http://gcc.gnu.org/ I cannot continue any further, aborting.

      And if I copy -lperl to $SYSROOT

      Use which C compiler? [gcc --sysroot=/usr/gcc-4.9.2/sysroot] /usr/gcc-4.9.2/bin/ld: warning: libm.so, needed by /usr/gcc-4.9.2/sysr +oot/usr/lib/libperl.so, not found (try using -rpath or -rpath-link) /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `log +' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `sqr +t' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `cei +l' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `flo +or' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `sca +lbnl' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `mod +f' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `fmo +d' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `cos +' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `sin +' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `ata +n2' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `pow +' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `exp +' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `ilo +gbl' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `fre +xp' collect2: error: ld returned 1 exit status Uh-oh, the C compiler 'gcc --sysroot=/usr/gcc-4.9.2/sysroot' doesn't s +eem to be working. /usr/gcc-4.9.2/bin/ld: warning: libm.so, needed by /usr/gcc-4.9.2/sysr +oot/usr/lib/libperl.so, not found (try using -rpath or -rpath-link) /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `log +' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `sqr +t' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `cei +l' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `flo +or' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `sca +lbnl' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `mod +f' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `fmo +d' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `cos +' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `sin +' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `ata +n2' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `pow +' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `exp +' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `ilo +gbl' /usr/gcc-4.9.2/sysroot/usr/lib/libperl.so: undefined reference to `fre +xp' collect2: error: ld returned 1 exit status Uh-oh, the C compiler 'gcc --sysroot=/usr/gcc-4.9.2/sysroot' doesn't s +eem to be working. You need to find a working C compiler. Either (purchase and) install the C compiler supplied by your OS vendo +r, or for a free C compiler try http://gcc.gnu.org/ I cannot continue any further, aborting.
Re: How To Link -lperl to Extensions During Build
by Anonymous Monk on May 12, 2015 at 00:26 UTC

    Please use the quick non-interactive Configure with -des, like Corion has shown above. For example

    ./Configure -des -Dprefix=... -Duseshrplib -Alddlflags='-shared -O2 -Wl,-E,-z,now'
    
    Are you sure you want a shared libperl? Do you need shared objects linked with -lperl? Perhaps it will suffice if libperl uses options -z now and/or -z global? (Android apparently has its own elf loader; dark territory I'm afraid.)

      Yes, I do need a shared libperl. Yes, I do need shared objects linked with -lperl, due to Android linker limitations (any symbols referenced in shared object must be in lib explicitly linked to object. )I will try z,-now as requested...but if it assumes linker can find symbols in loaded, non-linked libs, I fear it may not work

        Hmm. Not sure what the correct approach might be, but here's one possible hack to try:

        ./Configure -des -Dprefix=/foo -Dcc=gcc -Duseshrplib make install; make distclean ./Configure -des -Dprefix=/foo -Dcc=gcc -Duseshrplib \ -Alddlflags='-shared -O2 -Wl,-E,-L/foo/lib/perl5/5.20.2/armv7l-linux +-android/CORE,-as-needed,-lperl,-no-as-needed' make install
        This would compile and install perl twice, second time linking any shared objects against libperl. You may also want a ,-rpath,/foo... in the flags. But if you make a symlink in $KBOX/usr/lib to libperl.so, then neither -L nor -rpath should be required.