我有一个大约15,000行的Perl脚本,我想使用用PerlInterpreter编译的C++可执行文件来执行。
我试过了,跟着这些方向
我下载了Perl5.18源代码,并包含了用于perl.h和EXTERN.h的核心(安装)目录,以及core/win32和core/win32/include
然后,我尝试在Visual 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所以我向#define PERL_MICRO添加了一个perl.h语句
这将错误的数量减少到20个。
然而,所有的错误都来自Windows文件string.h和guidedef.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 发布于 2014-04-25 14:10:33
我会描述一下我在这个问题上知道的一些事情。我希望这能帮上忙。
首先,您应该指定在Windows上使用的Perl。在Windows上至少有两个我知道的:
第二,您要实现的是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::Embed与Utilities for embedding Perl in C/C++ applications有关。
我自己还没试过,但我想可以帮上忙。一旦我有时间调查这件事,我会带着更多的细节回来。
更新
具有嵌入式Perl解释器的应用程序列表:
ExtUtils::Embed在configure.in中使用(详见git clone git://git.irssi.org/irssi,或svn.irssi.org )configure.in中也使用ExtUtils::Embed。有关更多细节,hg clone https://vim.googlecode.com/hg/ vim。( 允许 通过Perl编写脚本.)https://stackoverflow.com/questions/23282491
复制相似问题