c++ - Perl XSPP - std::string 的多重定义

标签 c++ perl xs

我正试图公开一些 Google URL Library作为 perl 模块的功能。根据此处和其他地方的一些帖子,它看起来像 XSPP可能是一个很好的起点。这是我到目前为止创建的内容(从 googleurl 库的编译版本开始):

我创建了这个 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,它会生成对我来说合理的输出。

最佳答案

ExtUtils::Typemaps::Default 的文档清楚地说它已经包括ExtUtils::Typemaps::STL .如果您从 extra_typemaps 中删除后者,它应该一切正常。

关于c++ - Perl XSPP - std::string 的多重定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8141054/

相关文章:

perl - 使用 Perl XS 和 PerlIO 使旧库工作

c++ - 将函数对象传递给构造函数

perl - 本地在标准流/裸字文件句柄 : STDIN? 上做什么

perl - 单个字符串中对象返回的 HASH 元素

perl - 使用 Getopt::Long 时出现错误 "panic: attempt to copy freed scalar"

perl - 如何手动安装 XS 模块?

c++ - 我的 Perl XS 代码中的内存泄漏在哪里?

c++ - 哪些 C++ 编译器会自动定义 size_t 而无需包含 header ?

c++ - Dev C++ Mingw不再编译

c++ - 如何将全局 volatile 无符号字符传递给类