下面是我的 C 脚本。我不知道为什么找不到 EXTERN.h 和 perl.h,所以我在下面进行用户定义的链接。如果能解决这个问题,也请帮忙。
我正在尝试在 C 中嵌入 perl 脚本。该文件是 hell.c,是 hello.c 文件的缩写
希望从 c 运行嵌入式 perl 脚本。
尝试运行 gwan 时出现如下错误:
In file included from /usr/lib/perl/5.10.1/CORE/perl.h:2424:0,
from /home/qryos/Downloads/gwan_linux64-bit/0.0.0.0_8080/#0.0.0.0/csp/hell.c:9:
/usr/lib/perl/5.10.1/CORE/handy.h:108:0: warning: "bool" redefined
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/include/stdbool.h:33:0: note: this is the location of the previous definition
In file included from /usr/lib/perl/5.10.1/CORE/perl.h:3427:0,
from /csp/hell.c:9:
/usr/lib/perl/5.10.1/CORE/utf8.h:46:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'unsigned'
In file included from /csp/hell.c:9:0:
/usr/lib/perl/5.10.1/CORE/perl.h:4205:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'char'
/usr/lib/perl/5.10.1/CORE/perl.h:4207:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'char'
实际脚本
// ============================================================================
// C servlet sample for the G-WAN Web Application Server (http://trustleap.ch/)
// ----------------------------------------------------------------------------
// hello.c: just used with ab (ApacheBench) to benchmark a minimalist servlet
// ============================================================================
#include "gwan.h" // G-WAN exported functions
//#include <EXTERN.h>
//#include <perl.h>
#include "/usr/lib/perl/5.10.1/CORE/perl.h"
#include "/usr/lib/perl/5.10.1/CORE/EXTERN.h"
static PerlInterpreter *my_perl;
/*
int main(int argc, char **argv, char **env)
{
char *args[] = { NULL };
PERL_SYS_INIT3(&argc,&argv,&env);
my_perl = perl_alloc();
perl_construct(my_perl);
perl_parse(my_perl, NULL, argc, argv, NULL);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
call_argv("showtime", G_DISCARD | G_NOARGS, args);
perl_destruct(my_perl);
perl_free(my_perl);
PERL_SYS_TERM();
}
*/
int main(int argc, char *argv[], char *env[])
{
static char msg[] = "Hello, ANSI C!";
xbuf_ncat(get_reply(argv), msg, sizeof(msg) - 1);
/*
//PERL_SYS_INIT3(&argc,&argv,&env);
my_perl = perl_alloc();
perl_construct(my_perl);
perl_parse(my_perl, NULL, argc, argv, NULL);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
// call_argv("showtime", G_DISCARD | G_NOARGS, args);
perl_destruct(my_perl);
perl_free(my_perl);
PERL_SYS_TERM();
*/
return 200; // return an HTTP code (200:'OK')
}
更新,Gil 建议
我把这个放在了
#pragma include "/usr/lib/perl/5.10.1/CORE/"
#include <EXTERN.h>
#include <perl.h>
错误如下:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: hell.c
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/lib/perl/5.10.1/CORE/perl.h:2424:0,
from /home/example/Downloads/gwan/0.0.0.0_8080/#0.0.0.0/csp/hell.c:9:
/usr/lib/perl/5.10.1/CORE/handy.h:108:0: warning: "bool" redefined
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/include/stdbool.h:33:0: note: this is the location of the previous definition
In file included from /usr/lib/perl/5.10.1/CORE/perl.h:4829:0,
from /csp/hell.c:9:
/usr/lib/perl/5.10.1/CORE/proto.h:690:47: error: expected declaration specifiers or '...' before 'off64_t'
/usr/lib/perl/5.10.1/CORE/proto.h:697:21: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Perl_do_sysseek'
/usr/lib/perl/5.10.1/CORE/proto.h:702:21: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Perl_do_tell'
/usr/lib/perl/5.10.1/CORE/proto.h:6019:21: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Perl_PerlIO_tell'
/usr/lib/perl/5.10.1/CORE/proto.h:6020:53: error: expected declaration specifiers or '...' before 'off64_t'
/csp/hell.c:29:5: error: conflicting types for 'main'
/home/example/Downloads/gwan/include/gwan.h:36:13: note: previous declaration of 'main' was here
最佳答案
您在 Perl C header 中存在编译错误。你应该从这个开始。
看起来主要问题是缺少定义,查找 Perl 目录树依赖项并使用 G-WAN 添加任何缺少的目录 #pragma include
指令:
#pragma include "/usr/lib/perl/5.10.1/"
然后,您将能够使用 #include <perl.h>
.
请记住,G-WAN 不会编译无法使用 GCC 编译的程序。所以你的第一步可能是让你的 Perl 脚本嵌入作为一个独立的程序工作......然后尝试将它与 G-WAN 集成。
关于c - 如何在 gwan c 脚本中嵌入 perl 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27208982/