首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在C++应用程序中正确嵌入Perl解释器

如何在C++应用程序中正确嵌入Perl解释器
EN

Stack Overflow用户
提问于 2014-04-25 01:06:08
回答 1查看 1.8K关注 0票数 5

我有一个大约15,000行的Perl脚本,我想使用用PerlInterpreter编译的C++可执行文件来执行。

我试过了,跟着这些方向

我下载了Perl5.18源代码,并包含了用于perl.hEXTERN.h的核心(安装)目录,以及core/win32core/win32/include

然后,我尝试在Visual 2013中编译简单的C++项目

代码语言:javascript
复制
#include <EXTERN.h>               /* from the Perl distribution     */
#include <perl.h>                 /* from the Perl distribution     */

static PerlInterpreter *my_perl;  /***    The Perl interpreter    ***/

int main(int argc, char **argv, char **env)
{
  PERL_SYS_INIT3(&argc,&argv,&env);
  my_perl = perl_alloc();
  perl_construct(my_perl);
  PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
  perl_parse(my_perl, NULL, argc, argv, (char **)NULL);
  perl_run(my_perl);
  perl_destruct(my_perl);
  perl_free(my_perl);
  PERL_SYS_TERM();
}

该项目没有编译,产生了数百个错误,但最常见的错误是

代码语言:javascript
复制
missing config.h file included by perl.h

所以我向#define PERL_MICRO添加了一个perl.h语句

这将错误的数量减少到20个。

然而,所有的错误都来自Windows文件string.hguidedef.h,所以我不知道这些错误的根源是什么。

有人能向我提供关于如何为Perl脚本创建和构建C++解释器的任何信息吗?

剩下的错误是

代码语言:javascript
复制
Error   10  error C3861: 'my_memcmp': identifier not found  c:\program files (x86)\windows kits\8.1\include\shared\guiddef.h    161 1   

Error   3   error C2733: 'memmove_s' : second C linkage of overloaded function not allowed  c:\program files (x86)\microsoft visual studio 12.0\vc\include\string.h 136 1   

Error   4   error C2733: 'memmove' : second C linkage of overloaded function not allowed    c:\program files (x86)\microsoft visual studio 12.0\vc\include\string.h 139 1   

Error   2   error C2733: 'memcpy_s' : second C linkage of overloaded function not allowed   c:\program files (x86)\microsoft visual studio 12.0\vc\include\string.h 57  1   

Error   1   error C2733: 'memcpy' : second C linkage of overloaded function not allowed c:\program files (x86)\microsoft visual studio 12.0\vc\include\string.h 55  1   

Error   8   error C2732: linkage specification contradicts earlier specification for 'strstr'   c:\program files (x86)\microsoft visual studio 12.0\vc\include\string.h 228 1   

Error   7   error C2732: linkage specification contradicts earlier specification for 'strrchr'  c:\program files (x86)\microsoft visual studio 12.0\vc\include\string.h 226 1   

Error   6   error C2732: linkage specification contradicts earlier specification for 'strpbrk'  c:\program files (x86)\microsoft visual studio 12.0\vc\include\string.h 224 1   

Error   5   error C2732: linkage specification contradicts earlier specification for 'strchr'   c:\program files (x86)\microsoft visual studio 12.0\vc\include\string.h 222 1   

Error   9   error C2732: linkage specification contradicts earlier specification for 'memchr'   c:\program files (x86)\microsoft visual studio 12.0\vc\include\string.h 233 1   
EN

回答 1

Stack Overflow用户

发布于 2014-04-25 14:10:33

我会描述一下我在这个问题上知道的一些事情。我希望这能帮上忙。

首先,您应该指定在Windows上使用的Perl。在Windows上至少有两个我知道的:

  • 草莓Perl
  • Activestate Perl

第二,您要实现的是Embedding a Perl interpreter in a C/C++ application。我提到这一点,这样您可以在搜索有关它的文档时引用它。

全嵌入文档提供了有关这方面的一般信息。

如果您想使用ActivePerl在Windows上执行此操作,您可以查看在WIN32下嵌入Perl

对于Strawberry,这里是嵌入Perl的佩尔和尚的人有一个工作的例子

同时,请注意,使用perlwin32 perl文档页来设置具有适当路径的MSVC编译器可能是有用的。

最后,还有一本关于这个主题的书,名为扩展和嵌入Perl,有关这个主题的一些细节,您可能想看看它。在这本书中,第8章一般讨论在C中嵌入Perl,第9章讨论嵌入案例研究。

更新

通过阅读ExtUtils::MakeMaker文档,我发现这个部分看起来很有趣:

If you are running experiments with embedding perl as a library into other applications, you might find MakeMaker is not sufficient. You'd better have a look at ExtUtils::Embed which is a collection of utilities for embedding.

特别是ExtUtils::EmbedUtilities for embedding Perl in C/C++ applications有关。

我自己还没试过,但我想可以帮上忙。一旦我有时间调查这件事,我会带着更多的细节回来。

更新

具有嵌入式Perl解释器的应用程序列表:

  • 洋酒 --尤其是为您提供了编写通过其嵌入式Perl解释器运行的插件的可能性。这是一个有趣的例子,因为它也知道在Windows下工作。这里令人感兴趣的似乎是libpurple/plugins/perl,特别是Makefile.mingw,它应该包含关于如何在Windows上构建的信息
  • 伊尔西 -此处ExtUtils::Embedconfigure.in中使用(详见git clone git://git.irssi.org/irssi,或svn.irssi.org )
  • 维姆 -(在其configure.in中也使用ExtUtils::Embed。有关更多细节,hg clone https://vim.googlecode.com/hg/ vim。( 允许 通过Perl编写脚本.)
  • 伊辛加 - Icinga 允许在Perl中编写脚本
  • 纳古斯 -在这个上下文中有关Nagios的相关文章可以是在这里发现的
  • 收藏d - Makefile.amperl.c
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23282491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档