Mix Perl and C++/CLI

Perl is a language with many features to manipulate string. I always want to embed Perl into C program. But a conclusion in perlembed shocks me:

Corollary: you can't use Perl from your C program unless Perl has been compiled on your machine, or installed properly--that's why you shouldn't blithely copy Perl executables from machine to machine without also copying the lib directory.

I posted this on perlmonks and got excellent advice from Corion , and know in windows, all you need is just copy perl dll with c program. ;)

As monks help, I made a toy program embedded perl, and works fine! Thanks, perl! thanks perl community!

post main code here below, hope it could help guys who want to embed perl like me. ;)

#include "stdafx.h"
#include "Form1.h"
#pragma unmanaged
#include "perl.h"
#include "EXTERN.h"
#pragma managed
using namespace perl_form;
PerlInterpreter *my_perl;

int main(array ^args)
char *embed[] = {"", "-e", 0};
char *argss[] = { NULL };
PERL_SYS_INIT3((int *)NULL,(char ***)NULL,(char ***)NULL);
my_perl = perl_alloc();


// Enabling Windows XP visual effects before any controls are created

// Create the main window and run it
Application::Run(gcnew Form1());


return 0;

Leave a comment

About xiaoyafeng

user-pic I blog about Perl.