$ make
. . . stuff elided . . .
Kbh.o: In function `XS_Kbh_send_string':
/Work/Perl/Perlmonks/XS_linking/Kbh.c:173: undefined reference to `send_string'
/Work/Perl/Perlmonks/XS_linking/Kbh.c:173:(.text+0xb3): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `send_string'
collect2: error: ld returned 1 exit status
make: *** [Makefile:472: blib/arch/auto/Kbh/Kbh.dll] Error 1
####
$ objdump.exe -t Kbh.o
Kbh.o: file format pe-x86-64
SYMBOL TABLE:
[ 0](sec -2)(fl 0x00)(ty 0)(scl 103) (nx 1) 0x0000000000000000 Kbh.c
File
[ 2](sec 1)(fl 0x00)(ty 20)(scl 3) (nx 1) 0x0000000000000000 XS_Kbh_send_string
AUX tagndx 0 ttlsiz 0x0 lnnos 0 next 0
. . . elided . . .
[ 37](sec 0)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x0000000000000000 __imp_PL_thr_key
[ 38](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x0000000000000000 pthread_getspecific
[ 39](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x0000000000000000 Perl_sv_2pv_flags
[ 40](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x0000000000000000 send_string
[ 41](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x0000000000000000 Perl_croak_xs_usage
[ 42](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x0000000000000000 Perl_xs_handshake
[ 43](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x0000000000000000 Perl_newXS_deffile
[ 44](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x0000000000000000 Perl_xs_boot_epilog
$ objdump.exe -t send_string.o
send_string.o: file format pe-x86-64
SYMBOL TABLE:
[ 0](sec -2)(fl 0x00)(ty 0)(scl 103) (nx 1) 0x0000000000000000 send_string.cpp
File
[ 2](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 1) 0x0000000000000000 _Z11send_stringPKc
AUX tagndx 0 ttlsiz 0x0 lnnos 0 next 0
. . . elided . . .
####
$ make
cp lib/Kbh.pm blib/lib/Kbh.pm
cp Makefile.pl blib/lib/Makefile.pl
Running Mkbootstrap for Kbh ()
chmod 644 "Kbh.bs"
"/usr/bin/perl.exe" "/usr/lib/perl5/5.22/ExtUtils/xsubpp" -typemap "/usr/lib/perl5/5.22/ExtUtils/typemap" Kbh.xs > Kbh.xsc && mv Kbh.xsc Kbh.c
gcc -c -DPERL_USE_SAFE_PUTENV -D_GNU_SOURCE -U__STRICT_ANSI__ -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/mnt/share/maint/perl.x86_64/build=/usr/src/debug/perl-5.22.4-1 -fdebug-prefix-map=/mnt/share/maint/perl.x86_64/src/perl-5.22.4=/usr/src/debug/perl-5.22.4-1 -fwrapv -fno-strict-aliasing -fstack-protector-strong -D_FORTIFY_SOURCE=2 -DUSEIMPORTLIB -O3 -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" "-I/usr/lib/perl5/5.22/x86_64-cygwin-threads/CORE" Kbh.c
gcc -c -DPERL_USE_SAFE_PUTENV -D_GNU_SOURCE -U__STRICT_ANSI__ -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/mnt/share/maint/perl.x86_64/build=/usr/src/debug/perl-5.22.4-1 -fdebug-prefix-map=/mnt/share/maint/perl.x86_64/src/perl-5.22.4=/usr/src/debug/perl-5.22.4-1 -fwrapv -fno-strict-aliasing -fstack-protector-strong -D_FORTIFY_SOURCE=2 -DUSEIMPORTLIB -O3 -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" "-I/usr/lib/perl5/5.22/x86_64-cygwin-threads/CORE" send_string.c
rm -f blib/arch/auto/Kbh/Kbh.dll
g++ --shared -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -fstack-protector-strong Kbh.o send_string.o -o blib/arch/auto/Kbh/Kbh.dll \
/usr/lib/perl5/5.22/x86_64-cygwin-threads/CORE/cygperl5_22.dll \
chmod 755 blib/arch/auto/Kbh/Kbh.dll
"/usr/bin/perl.exe" -MExtUtils::Command::MM -e 'cp_nonempty' -- Kbh.bs blib/arch/auto/Kbh/Kbh.bs 644
####
$ cat Kbh.xs
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include "send_string.h"
MODULE = Kbh PACKAGE = Kbh
PROTOTYPES: DISABLE
void
send_string(s)
const char * s
TYPEMAP: <
void send_string(const char* str) {
puts(str);
}
$ cat send_string.h
void send_string(const char* str);
$ cat lib/Kbh.pm
package Kbh;
our $VERSION = '0.01';
require XSLoader;
XSLoader::load('Kbh', $VERSION);
1;
$ cat Makefile.pl
use ExtUtils::MakeMaker;
WriteMakefile (
NAME=>'Kbh',
VERSION_FROM =>'lib/Kbh.pm',
OBJECT => 'Kbh.o send_string.o',
)
$ perl Makefile.pl
Generating a Unix-style Makefile
Writing Makefile for Kbh
Writing MYMETA.yml and MYMETA.json
$ make
cp Makefile.pl blib/lib/Makefile.pl
cp lib/Kbh.pm blib/lib/Kbh.pm
Running Mkbootstrap for Kbh ()
chmod 644 "Kbh.bs"
"/usr/bin/perl.exe" "/usr/lib/perl5/5.22/ExtUtils/xsubpp" -typemap "/usr/lib/perl5/5.22/ExtUtils/typemap" Kbh.xs > Kbh.xsc && mv Kbh.xsc Kbh.c
gcc -c -DPERL_USE_SAFE_PUTENV -D_GNU_SOURCE -U__STRICT_ANSI__ -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/mnt/share/maint/perl.x86_64/build=/usr/src/debug/perl-5.22.4-1 -fdebug-prefix-map=/mnt/share/maint/perl.x86_64/src/perl-5.22.4=/usr/src/debug/perl-5.22.4-1 -fwrapv -fno-strict-aliasing -fstack-protector-strong -D_FORTIFY_SOURCE=2 -DUSEIMPORTLIB -O3 -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" "-I/usr/lib/perl5/5.22/x86_64-cygwin-threads/CORE" Kbh.c
gcc -c -DPERL_USE_SAFE_PUTENV -D_GNU_SOURCE -U__STRICT_ANSI__ -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/mnt/share/maint/perl.x86_64/build=/usr/src/debug/perl-5.22.4-1 -fdebug-prefix-map=/mnt/share/maint/perl.x86_64/src/perl-5.22.4=/usr/src/debug/perl-5.22.4-1 -fwrapv -fno-strict-aliasing -fstack-protector-strong -D_FORTIFY_SOURCE=2 -DUSEIMPORTLIB -O3 -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" "-I/usr/lib/perl5/5.22/x86_64-cygwin-threads/CORE" send_string.c
rm -f blib/arch/auto/Kbh/Kbh.dll
g++ --shared -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -fstack-protector-strong Kbh.o send_string.o -o blib/arch/auto/Kbh/Kbh.dll \
/usr/lib/perl5/5.22/x86_64-cygwin-threads/CORE/cygperl5_22.dll \
chmod 755 blib/arch/auto/Kbh/Kbh.dll
"/usr/bin/perl.exe" -MExtUtils::Command::MM -e 'cp_nonempty' -- Kbh.bs blib/arch/auto/Kbh/Kbh.bs 644