3

我正在尝试将一些Google URL 库功能公开为 perl 模块。根据这里和其他地方的一些帖子,看起来XSPP可能是一个不错的起点。这是我到目前为止创建的内容(从 googleurl lib 的编译版本开始):

我创建了这个 xspp 文件(为简洁起见省略了一些方法):

#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();
};

我创建了这个 Makefile.PL 文件:

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',
);

然后我运行:

perl Makefile.PL && ./Build

..并得到以下错误:

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.

有 xspp 经验的人是否知道可能导致此错误的原因?我可以在上面的 GURL.xsp 文件上成功运行 xspp,它产生的输出对我来说看起来很合理。

4

1 回答 1

6

ExtUtils::Typemaps::Default的文档清楚地表明它已经包含ExtUtils::Typemaps::STL。如果你从你的 中删除后者extra_typemaps,它应该都可以工作。

于 2011-11-15T19:16:01.267 回答