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

Hi,
I've written a test extension (Foo), the full source of which is contained within the readmore tags below my sig. It's a valid source distro - in that it can be built with 'perl Makefile.PL', 'make test' and 'make install'.

It's a bare-bones and useless extension that contains just one XSub named 'foo()'. When I build Foo, I note that the Foo.dll (shared object) that is built does not export 'foo()'. What do I need to do in order that Foo.dll *does* export 'foo()'.

Cheers,
Rob
## Foo.pm ## package Foo; use strict; require Exporter; *import = \&Exporter::import; require DynaLoader; $Foo::VERSION = '0.01'; DynaLoader::bootstrap Foo $Foo::VERSION; @Foo::EXPORT = qw(foo); @Foo::EXPORT_OK = (); sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaki +ng 1; __END__ ## Makefile.PL ## use ExtUtils::MakeMaker; my %options = %{ { 'TYPEMAPS' => [ 'C:\\perl510_M\\5.10.0\\lib\\ExtUtils\\typemap' ], 'NAME' => 'Foo', 'INC' => '-IC:/temp/Foo_build', 'VERSION' => '0.01' } }; WriteMakefile(%options); # Remove the Makefile dependency. Causes problems on a few systems. sub MY::makefile { '' } __END__ ## test.pl ## use Foo; $x = 17; $y = 31; $z = foo($x, $y); if($z == 48){print "ok 1\n"} else {print "not ok 1 $z\n"} __END // Foo.xs // #include "EXTERN.h" #include "perl.h" #include "XSUB.h" int foo(int x, int y) { return x + y; } MODULE = Foo PACKAGE = Foo PROTOTYPES: DISABLE int foo (x, y) int x int y

Replies are listed 'Best First'.
Re: [XS on Win32] How to have the extension's dll export its symbols.
by BrowserUk (Patriarch) on Mar 05, 2008 at 11:57 UTC
      As regards point 1 :
      The def file is auto-generated during the 'make' process - which is 'dmake', in my case. How does one influence the contents of the def file that is created by that automated procedure ?

      As regards point 2 :
      I changed Foo.xs so that it now has:
      #include "EXTERN.h" #include "perl.h" #include "XSUB.h" int __declspec(dllexport) foo(int x, int y) { return x + y; } MODULE = Foo PACKAGE = Foo PROTOTYPES: DISABLE int foo (x, y) int x int y
      But, according to dumpbin /exports, 'Foo.dll' still exports only '_boot_Foo' and 'boot_Foo'.

      I'm using the MinGW compiler - don't know if that has any bearing on the matter ... apologies if I'm being dense.

      Cheers,
      Rob
        I'm using the MinGW compiler ...

        If you follow the link I belatedly added to my response you'll see that dllexport is an MS specific extension. Presumably the __declspec() bit is a part of some standard otherwise you'd be getting an error.

        Whether MinGW supports a similar extension I don't know. They can build .sos an .dlls so must have encountered similar problems.

        1. How does one influence the contents of the def file that is created by that automated procedure ?

          I looked that up a while ago. There is mention in the pod for E::MM of a coniguration attribute DL_FUNCS which seems to be something to do with it.

        2. I changed Foo.xs so that it now has:

          See above:)


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.