develooper Front page | perl.perl5.porters | Postings from August 2014

[perl #122550] Impossible to detect perl CFLAGS and LDFLAGS for cross-compilation of plugins

From:
John Spencer
Date:
August 20, 2014 16:17
Subject:
[perl #122550] Impossible to detect perl CFLAGS and LDFLAGS for cross-compilation of plugins
Message ID:
rt-4.0.18-13876-1408296333-964.122550-75-0@perl.org
# New Ticket Created by  John Spencer 
# Please include the string:  [perl #122550]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=122550 >


This is a bug report for perl from maillist-perl@barfooze.de,
generated with the help of perlbug 1.39 running under perl 5.16.3.


-----------------------------------------------------------------
[Please describe your issue here]

due to lack of pkg-config files, it's impossible to find out the
right CFLAGS and LDFLAGS to add when trying to cross-compile software
that uses perl plugins and intends to link against libperl.

after several hours of searching the documentation/web, the only 
vendor-provided way to query the required flags I found is:

perl -MExtUtils::Embed -e ccopts
perl -MExtUtils::Embed -e ldopts

however those can only be used for the host installation.
for a cross-compiled perl, the target perl binary cannot even be
executed on the host.
By invoking the host perl with those flags, cross-compilation will
break trying to include host headers and libraries which are typically
built for a different architecture.
Since libperl.a/.so reside in a customized subdir in /var or /lib,
there's no canonical path to add so -lperl could be found.

Suggested fix:
either provide a pkg-config (.pc) together with perl, installed into
the standard pkg-config path; or
create a symlink of libperl.a and the directory containing perl.h in the 
canonical lib and include dirs.
so $prefix/lib/libperl.a -> $prefix/lib/perl5/core_perl/CORE/libperl.a
and $prefix/include/perl -> $prefix/lib/perl5/core_perl/CORE
(note that the exact path lib/perl5/core_perl/CORE/ depends on user-chosen
settings during perl compilation.)

But TBH perl should just supply a .pc file like anyone else does.
the pkg-config format is well-documented, understood, and widely supported.
there are even several available implementation, for example the BSD-
licensed "pkgconf". pkgconf and pkg-config support cross-compilation
out of the box using the PKG_CONFIG_SYSROOT_DIR environment variable.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
     category=library
     severity=high
---
Site configuration information for perl 5.16.3:

Configured by root at Wed Nov  6 14:51:20 UTC 2013.

Summary of my perl5 (revision 5 version 16 subversion 3) configuration:

   Platform:
     osname=linux, osvers=3.11.6, archname=x86_64-linux
     uname='linux sabotage 3.11.6 #1 smp sun oct 27 00:36:15 utc 2013 
x86_64 gnulinux '
     config_args='-des -Accflags=-D_GNU_SOURCE -D_BSD_SOURCE -fPIC 
-fdata-sections -ffunction-sections -Os -g0 -fno-unwind-tables 
-fno-asynchronous-unwind-tables -Wa,--noexecstack -ftree-dce 
-Aldflags=-s -Wl,--gc-sections -Wl,-z,relro,-z,now -Dprefix=/ 
-Dvendorprefix=/ -Dinstallprefix= -Dprivlib=//lib/perl5/core_perl 
-Darchlib=//lib/perl5/core_perl -Dsitelib=//lib/perl5/site_perl 
-Dsitearch=//lib/perl5/site_perl -Dvendorlib=//lib/perl5/vendor_perl 
-Dvendorarch=//lib/perl5/vendor_perl -Dscriptdir=//bin 
-Dsitescript=//bin -Dvendorscript=//bin -Dinc_version_list=none 
-Dman1dir=//share/man/man1perl -Dman1ext=1perl 
-Dman3dir=//share/man/man3perl -Dman3ext=3perl'
     hint=recommended, useposix=true, d_sigaction=define
     useithreads=undef, usemultiplicity=undef
     useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
     use64bitint=define, use64bitall=define, uselongdouble=undef
     usemymalloc=n, bincompat5005=undef
   Compiler:
     cc='cc', ccflags ='-D_GNU_SOURCE -D_BSD_SOURCE -fPIC 
-fdata-sections -ffunction-sections -Os -g0 -fno-unwind-tables 
-fno-asynchronous-unwind-tables -Wa,--noexecstack -ftree-dce 
-fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
     optimize='-O2',
     cppflags='-D_GNU_SOURCE -D_BSD_SOURCE -fPIC -fdata-sections 
-ffunction-sections -Os -g0 -fno-unwind-tables 
-fno-asynchronous-unwind-tables -Wa,--noexecstack -ftree-dce 
-fno-strict-aliasing -pipe'
     ccversion='', gccversion='4.7.3', gccosandvers=''
     intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
     ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
     alignbytes=8, prototype=define
   Linker and Libraries:
     ld='cc', ldflags =' -s -Wl,--gc-sections -Wl,-z,relro,-z,now'
     libpth=/lib /usr/lib
     libs=-lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lpthread
     perllibs=-ldl -lm -lcrypt -lutil -lc -lpthread
     libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
     gnulibc_version=''
   Dynamic Linking:
     dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
     cccdlflags='-fPIC', lddlflags='-shared -O2'

Locally applied patches:


---
@INC for perl 5.16.3:
     //lib/perl5/site_perl
     //lib/perl5/vendor_perl
     //lib/perl5/core_perl
     .

---
Environment for perl 5.16.3:
     HOME=/home/js
     LANG (unset)
     LANGUAGE (unset)
     LD_LIBRARY_PATH (unset)
     LOGDIR (unset)
     PATH=/local/bin:/bin
     PERL_BADLANG (unset)
     SHELL=/bin/bash




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About