下面是我的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')
}
更新,吉尔建议
我已经加入了这个
#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
答案 0 :(得分:0)
您在Perl C标头中有编译错误。你应该从这开始。
看起来主要问题是缺少定义,查找Perl目录树依赖项并使用G-WAN #pragma include
指令添加任何缺少的目录:
#pragma include "/usr/lib/perl/5.10.1/"
然后,您将能够使用#include <perl.h>
。
请记住,G-WAN不会编译无法使用GCC编译的程序。因此,您的第一步可能是将Perl脚本嵌入作为独立程序工作......然后尝试将其与G-WAN集成。