Search code examples
c++perlxs

Perl XSPP - multiple definition of std::string


I'm attempting to expose some of the Google URL Library functionality as a perl module. Based on some posts here and elsewhere, it looks like XSPP might be a good place to start. Here's what I've created so far (starting with a compiled version of the googleurl lib):

I created this xspp file (some methods omitted for brevity):

#include "gurl.h"
%typemap{std::string};
%typemap{bool};
%module{Google::URL};
class GURL
{
  %name{new} GURL(std::string& url);
  ~GURL();
  bool is_valid();
  bool is_empty();
  std::string spec();
  std::string possibly_invalid_spec();
  std::string scheme();
  std::string username();
  std::string password();
  std::string host();
  std::string port();
  std::string path();
  std::string query();
  std::string ref();
  bool has_scheme();
  bool has_username();
  bool has_password();
  bool has_host();
  bool has_port();
  bool has_path();
  bool has_query();
  bool has_ref();
};

And I created this Makefile.PL file:

use 5.012;
use Module::Build::WithXSpp;
my $build = Module::Build::WithXSpp->new(
  module_name       => 'Google::URL::GURL',
  license           => 'perl',
  extra_typemap_modules => {
    'ExtUtils::Typemap::Default' => '0.01',
    'ExtUtils::Typemap::STL' => '0.01',
  },
  extra_linker_flags => '-L../googleurl -lgoogleurl',
  extra_compiler_flags => '-I. -I.. -I../googleurl -I../googleurl/base -I../googleurl/src',
);

Then I run:

perl Makefile.PL && ./Build

..and get the following error:

WARNING: the following files are missing in your kit:
    GURL.xs 
Please inform the author.

Created MYMETA.yml and MYMETA.json
Creating new 'Build' script for 'Google-URL-GURL' version '0.01' 
Building Google-URL-GURL
Processing XS typemap files...
Multiple definition of ctype 'std::string' in TYPEMAP section at ~/lib/perlbrew/perls/perl-5.14.2/lib/site_perl/5.14.2/ExtUtils/Typemaps.pm line 819.

Does anyone with xspp experience have any idea what could be causing this error? I can successfully run xspp on my GURL.xsp file above and it produces output that looks reasonable to me.


Solution

  • The documentation of ExtUtils::Typemaps::Default clearly says it already includes ExtUtils::Typemaps::STL. If you remove the latter from your extra_typemaps, it should all work.