【问题标题】:How to correctly embed a Perl interpreter in a C++ application on Windows如何在 Windows 上的 C++ 应用程序中正确嵌入 Perl 解释器
【发布时间】:2014-04-25 01:06:08
【问题描述】:

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

我试过了,关注these directions

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

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

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

项目没有编译,出现数百个错误,但最普遍的错误是

missing config.h file included by perl.h

所以我在perl.h 中添加了#define PERL_MICRO 语句

这将错误数量减少到 20 个

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

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


剩下的错误是

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   

【问题讨论】:

  • 您似乎在随意更改内容以试图摆脱错误消息;这不是一个好的工作方式。这些消息本身不是问题,但它们会提醒您需要解决的问题。我不确定您的问题的解决方案是什么,但破解 Perl 发布文件不是其中的一部分。如果您想为构建定义 PERL_MICRO,那么您需要修改您的 Visual Studio 项目来定义它。头文件构成了 Perl 编译器/解释器接口的定义,您不能随意更改它们。

标签: c++ perl visual-studio


【解决方案1】:

我将描述一些我知道的关于这个主题的事情。我希望这会有所帮助。

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

其次,您要达到的目标是Embedding a Perl interpreter in a C/C++ application。我提到了这一点,以便您在搜索有关它的文档时可以参考它。

perlembed 文档提供了有关此的一般信息。

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

对于 Strawberry Perl,someone on Perlmonks has a working example 在此处将 Perl 嵌入 Windows。

同时,请注意遵循perlwin32 perl 文档页面可能会很有用,以便使用适当的路径设置 MSVC 编译器。

最后,还有一本关于该主题的书,名为Extending and Embedding Perl,您可能想查看有关该主题的一些详细信息。在本书中,第 8 章讨论了将 Perl 嵌入到 C 中的一般性讨论,第 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 解释器的应用程序列表:

【讨论】:

  • 谢谢,我会在这些文档中寻找解决方案。我安装了 Strawberry Perl 和 Activestate Perl。至于来源,我不确定我下载的是哪个,因为网站perl.org/get.html(来源部分)没有指定它是哪个版本。现在我决定放弃 perl 并用 C 重新编写应用程序,因为这是我应用程序的最终目标。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-11-10
  • 1970-01-01
  • 1970-01-01
  • 2019-06-23
  • 2011-04-23
  • 2011-01-04
  • 1970-01-01
相关资源
最近更新 更多