Mail Archives: cygwin/2001/10/31/20:04:46
Dear Ladies and Gentlemen,
I am writing to ask if anyone has compiled a Perl XSUB or built C
applications with an embedded Perl Interpreter using the ExtUtils::Embed
module ?
The perlembed man pages recommend compiling an application with an
embedded Perl interpeter by
gcc -o x x.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
However, while I have an application that compiles (and runs) under
Unix(FreeBSD) perl 5.0005_03, it complains about
missing library lperl (probably harmless) and
undefined symbol my_perl
(the application has no symbol my_perl in it's source), under Perl 5.6.1
and Cygnus (very recent distro).
If I put dTHX before dSP (as has been recommended) there are heaps of
undefined symbols from the Dynaloader.
I realise that this is lacking somewhat in detail. I will gladly send
more if necessary.
At this stage I do not know whether the problem is in the code, or in
the environment. Unfortunately I have no reference Perl 5.6.1 system to
test against.
You can see the application below.
--
------------------------------------------------------------------------
Stanley Hopcroft IP Australia
Network Specialist
+61 2 6283 3189 +61 2 6281 1353 (FAX) Stanley DOT Hopcroft AT IPAustralia DOT Gov DOT AU
------------------------------------------------------------------------
Flugg's Law:
When you need to knock on wood is when you realize that the
world is composed of vinyl, naugahyde and aluminum.
#include <EXTERN.h>
#include <perl.h>
#include <fcntl.h>
#include <string.h>
/* include PERL xs_init code for module and C library support */
#if defined(__cplusplus)
#define is_cplusplus
#endif
#ifdef is_cplusplus
extern "C" {
#endif
#define NO_XSLOCKS
#include <XSUB.h>
#ifdef is_cplusplus
}
# ifndef EXTERN_C
# define EXTERN_C extern "C"
# endif
#else
# ifndef EXTERN_C
# define EXTERN_C extern
# endif
#endif
EXTERN_C void xs_init _((void));
EXTERN_C void boot_DynaLoader _((CV* cv));
EXTERN_C void
xs_init(void)
{
char *file = __FILE__;
dXSUB_SYS;
/* DynaLoader is a special case */
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
}
static PerlInterpreter *perl = NULL;
int main(int argc, char **argv, char **env){
char *embedding[] = { "", "p1.pl" };
char plugin_output[1024];
char buffer[512];
char tmpfname[32];
char fname[32];
char *args[] = {"","0", "", "", NULL };
FILE *fp;
char command_line[80];
char *ap ;
int exitstatus;
int pclose_result;
dSP;
if((perl=perl_alloc())==NULL){
snprintf(buffer,sizeof(buffer),"Error: Could not allocate memory for embedded Perl interpreter!\n");
buffer[sizeof(buffer)-1]='\x0';
printf("%s\n", buffer);
exit(1);
}
perl_construct(perl);
exitstatus=perl_parse(perl,xs_init,2,embedding,NULL);
if(!exitstatus) {
exitstatus=perl_run(perl);
while(printf("Enter file name: ") && fgets(command_line, 80, stdin)) {
/* call the subroutine, passing it the filename as an argument */
command_line[strlen(command_line) -1] = '\0';
strncpy(fname,command_line,strcspn(command_line," "));
fname[strcspn(command_line," ")] = '\x0';
args[0] = fname ;
args[3] = command_line + strlen(fname) + 1 ;
/* generate a temporary filename to which stdout can be redirected. */
sprintf(tmpfname,"/tmp/embedded%d",getpid());
args[2] = tmpfname;
/* call our perl interpreter to compile and optionally cache the command */
perl_call_argv("Embed::Persistent::eval_file", G_DISCARD | G_EVAL, args);
perl_call_argv("Embed::Persistent::run_package", G_DISCARD | G_EVAL, args);
/* check return status */
if(SvTRUE(ERRSV)){
pclose_result=-2;
printf("embedded perl ran %s with error %s\n",fname,SvPV(ERRSV,PL_na));
}
/* read back stdout from script */
fp=fopen(tmpfname, "r");
/* default return string in case nothing was returned */
strcpy(plugin_output,"(No output!)");
fgets(plugin_output,sizeof(plugin_output)-1,fp);
plugin_output[sizeof(plugin_output)-1]='\x0';
fclose(fp);
unlink(tmpfname);
printf("embedded perl plugin output was %d,%s\n",pclose_result, plugin_output);
}
}
PL_perl_destruct_level = 0;
perl_destruct(perl);
perl_free(perl);
exit(exitstatus);
}
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -