soren.hein has asked for the wisdom of the Perl Monks concerning the following question:
I'm on 64-bit perl 5.14.2 and cygwin on 64-bit Windows 7.
I'm trying to create a simple test case for the following problem, and it's driving me mad. I actually had it working at some point, but I must have changed something that seemed immaterial, and I didn't make a copy...
1. simplelib.c has a pure C function, own_function(), and a header file dll.h. It gets compiled and turned into simplelib.dll.
2. standalone.c links against simplelib.dll and calls own_function(). This works.
3. glue.xs includes dll.h and calls own_function(). Later on, the glue is going to become more complex, but that's the idea.
4. I want to compile glue.xs AND add simplelib.dll into Glue.dll.
5. I want to use Dynaloader from Perl to access Glue.dll through the XS function own_function().
The mechanics work, as long as glue.xs doesn't actually call own_function(). But as soon as I uncomment that one line, the loader complains,
"Can't load lib/Glue.dll for 'Glue::IF': No such file or directory..."
The file does exist, as it's in the same place with the same name. But uncommenting the call to the DLL function own_function() causes the problem.
Here are the files.
simplelib.c
-----------
#include <stdio.h> #include "dll.h" extern "C" int __stdcall own_function(int arg) { printf("Hello from simplelib, arg = %d\n", arg); return 0; }
dll.h
-----
extern "C" int __stdcall own_function(int arg);Compilation
-----------
g4 -c -I. -I/home/soren.hein/include -DPERL_USE_SAFE_PUTENV -U__STRICT +_ANSI__ -g -fno-strict-aliasing -pipe -fstack-protector -DUSEIMPORTLI +B -O3 "-I/usr/lib/perl5/5.14/i686-cygwin-threads-64int/CORE" simpleli +b.c g4 --shared -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--en +able-auto-image-base -L/usr/local/lib -fstack-protector simplelib.o - +o simplelib.dll
standalone.c
------------
#include <stdio.h> #include "dll.h" int main() { int ret; printf("Hello from main\n"); ret = own_function(5); }
Compilation
-----------
g4 -c -I. -I/home/soren.hein/include -DPERL_USE_SAFE_PUTENV -U__STRICT +_ANSI__ -g -fno-strict-aliasing -pipe -fstack-protector -DUSEIMPORTLI +B -O3 "-I/usr/lib/perl5/5.14/i686-cygwin-threads-64int/CORE" standalo +ne.c g4 -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto +-image-base -L/usr/local/lib -fstack-protector standalone.o -o standa +lone /home/soren.hein/testcase/xs/simplelib.dll
./standalone.exe yields
Hello from main Hello from simplelib, arg = 5
glue.xs
-------
#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "dll.h" MODULE = Glue::IF PACKAGE = Glue::IF PROTOTYPES: ENABLE void own_function(inlist) SV * inlist INIT: int i, ret; PPCODE: printf("Hello from XS\n"); i = 17; ret = own_function(i);
where the last line is either like that, or commented out.
Compilation into Glue.dll
-------------------------
/usr/bin/perl.exe /usr/lib/perl5/5.14/ExtUtils/xsubpp -typemap /usr/li +b/perl5/5.14/ExtUtils/typemap glue.xs > glue.xsc && mv glue.xsc glue. +c g4 -c -I. -I/home/soren.hein/include -DPERL_USE_SAFE_PUTENV -U__STRICT +_ANSI__ -g -fno-strict-aliasing -pipe -fstack-protector -DUSEIMPORTLI +B -O3 "-I/usr/lib/perl5/5.14/i686-cygwin-threads-64int/CORE" glue.c rm -f DDS_IF.dll g4 --shared -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--en +able-auto-image-base -L/usr/local/lib -fstack-protector glue.o -o Glu +e.dll /usr/lib/perl5/5.14/i686-cygwin-threads-64int/CORE/cygperl5_14. +dll /home/soren.hein/testcase/xs/simplelib.dll
I'm not showing the Perl to call it all, but it does get to "Hello from XS" with the critical line commented out. With the line enabled, the DLL compiles, but Dynaloader doesn't want to load it anymore. Help!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XS with DLL
by Anonymous Monk on Jun 04, 2014 at 22:06 UTC | |
by soren.hein (Initiate) on Jun 05, 2014 at 11:09 UTC | |
by syphilis (Archbishop) on Jun 05, 2014 at 15:33 UTC | |
by soren.hein (Initiate) on Jun 05, 2014 at 19:40 UTC |