您的位置:首页 > 编程语言 > C语言/C++

perl embeded into c++ 完全攻略

2005-06-07 15:43 302 查看
perl embeded into c++
document.title="perl embeded into c++ - "+document.title
完全攻略
step 1:
要想在Microsoft Developer Studio中使用perl首先要运行:

perl -MextUtils::Embed -e xsinit

生成perlxsi.c(perlxsi.cpp)文件.
Step2:
创建工程,选中创建空白工程的选项,再添加自己的源代码,这样产生的工程不会有多余的文件,默认也不使用预编译头。
Project->Win32 Consol Application-> an empty project
step3
然后在生成的vc工程中将perlxsi.c和perl.lib文件添加到Source Files文件夹中,这里注意perl.lib根据版本的不同也有不同,要到安装perl的文件夹下perl/lib/core中具体查找,比如我的就是perl58.lib。
具体做法: 在VC打开时,这样添加project->Add to project->Files
除此之外,还要在vc的工具-〉选项-〉目录中将相关的库文件添加进来,我是这样设的:

Executable files:x:/perl/bin
Include files:x:/perl/lib/core
Library files:x:/perl/lib/core

Step4
测试程序如下
#include "EXTERN.h"
#include "perl.h"

static PerlInterpreter *my_perl;

int main(int argc, char **argv)
{
char* command_line[] = {"", "-e","print /"Hello from C!//n/";"};

my_perl = perl_alloc();
perl_construct(my_perl);
perl_parse(my_perl, NULL, 3, command_line, (char **)NULL);
perl_run(my_perl);
perl_destruct(my_perl);
perl_free(my_perl);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: