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!


In reply to XS with DLL by soren.hein

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.