我有一个大约15000行的Perl脚本,我想用C++编译的Windows可执行文件中的PerlInterpreter
来执行。
我试过了,按照的指示
我下载了Perl5.18源代码,并包含了核心(安装)目录,用于perl.h
和EXTERN.h
,以及core/win32
和core/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.h
和guidedef.h
所以我不知道这些错误的来源是什么
有人能为我提供一些关于如何为Perl脚本创建和构建C++解释器的信息吗?
剩下的错误是
Error 10 error C3861: 'my_memcmp': identifier not found c:program files (x86)windows kits8.1includesharedguiddef.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.0vcincludestring.h 136 1
Error 4 error C2733: 'memmove' : second C linkage of overloaded function not allowed c:program files (x86)microsoft visual studio 12.0vcincludestring.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.0vcincludestring.h 57 1
Error 1 error C2733: 'memcpy' : second C linkage of overloaded function not allowed c:program files (x86)microsoft visual studio 12.0vcincludestring.h 55 1
Error 8 error C2732: linkage specification contradicts earlier specification for 'strstr' c:program files (x86)microsoft visual studio 12.0vcincludestring.h 228 1
Error 7 error C2732: linkage specification contradicts earlier specification for 'strrchr' c:program files (x86)microsoft visual studio 12.0vcincludestring.h 226 1
Error 6 error C2732: linkage specification contradicts earlier specification for 'strpbrk' c:program files (x86)microsoft visual studio 12.0vcincludestring.h 224 1
Error 5 error C2732: linkage specification contradicts earlier specification for 'strchr' c:program files (x86)microsoft visual studio 12.0vcincludestring.h 222 1
Error 9 error C2732: linkage specification contradicts earlier specification for 'memchr' c:program files (x86)microsoft visual studio 12.0vcincludestring.h 233 1
我将描述我对这个主题的一些了解。我希望这会有所帮助。
首先,您应该指定在Windows上使用的Perl。据我所知,在Windows上至少有两个:
- 草莓Perl
- 活动状态Perl
其次,你想要达到的是Embedding a Perl interpreter in a C/C++ application
。我提到这一点是为了让你在搜索有关它的文档时可以参考它。
perlembed文档提供了有关此方面的一般信息。
如果你想用ActivePerl在Windows上实现这一点,你可以看看WIN32下的嵌入式Perl。
对于Strawberry Perl,Perlmonks上的某个人在这里有一个在Windows上嵌入Perl的工作示例。
同时,请注意,按照perlwin32perl文档页面设置具有适当路径的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解释器的应用程序列表:
- Pidgin特别为您提供了编写插件的可能性,这些插件通过其嵌入式Perl解释器运行。这是一个有趣的例子,因为它也可以在Windows下工作。这里感兴趣的似乎是libpurple/plugins/perl,尤其是Makefile.mingw,它应该包含关于如何在Windows上构建的信息
- Irssi-此处
ExtUtils::Embed
用于configure.in
(有关详细信息,请参阅git clone git://git.irssi.org/irssi
或svn.Irssi.org) - Vim-(在
configure.in
中也使用ExtUtils::Embed
。有关更多详细信息,请参阅hg clone https://vim.googlecode.com/hg/ vim
。Vim还允许通过Perl编写脚本。) - Icinga-Icinga允许使用Perl编写脚本
- Nagios-在这里可以找到关于Nagios的相关文章
- collectd-Makefile.am和perl.c