也许有人能帮我理解。发生此错误的原因。我正在尝试构建C++代码,使用Inline::CPP。
示例如下:
#!/usr/bin/env perl
package main v0.1.0;
use strict;
use warnings;
use Inline(
CPP => <<'CPP',
#undef seekdir
#include <sstream>
CPP
# ccflags => '-std=c++11',
ccflags => '-std=gnu++11',
clean_after_build => 0,
clean_build_area => 0,
);
1;
__END__
此代码在linux下编译时没有错误,但在strawberry perl 5.26.2 x64下会产生以下错误:
"D:\devel\perl\perl\bin\perl.exe" -MExtUtils::Command -e mv -- _2_pl_0f1f.xsc _2_pl_0f1f.c
g++ -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -D__USE_MINGW_ANSI_STDIO -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fwrapv -fno-strict-aliasing -mms-bitfields -xc++ -c -I"D:/downloads/cpp-adaptive/cppAdaptive2/inline-src" -std=gnu++11 -s -O2 -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\" "-ID:\devel\perl\perl\lib\CORE" _2_pl_0f1f.c
In file included from _2_pl_0f1f.xs:11:0:
D:\devel\perl\perl\lib\CORE/perl.h:3544:45: error: expected ')' before '*' token
# define PERL_GET_THX ((PerlInterpreter *)PERL_GET_CONTEXT)
^
D:\devel\perl\perl\lib\CORE/perl.h:3544:45: error: expected ')' before '*' token
D:\devel\perl\perl\lib\CORE/perl.h:3544:45: error: expected ')' before '*' token
D:\devel\perl\perl\lib\CORE/perl.h:3544:45: error: expected ')' before '*' token
D:\devel\perl\perl\lib\CORE/perl.h:3544:29: error: expected ';' at end of member declaration
# define PERL_GET_THX ((PerlInterpreter *)PERL_GET_CONTEXT)
... and so on ...
也许有人已经解决了类似的问题?
发布于 2018-06-04 11:54:40
出现此错误的原因是,<sstream>
恰好在内联函数中使用了setbuf
,隐式添加了哪个头文件(可能是XSUB.h
或perl.h
?)已重新定义(使用预处理器#define
)。
这种重新定义突然中断,因为它使用了PerlInterpreter
类型,该类型是在不同的名称空间中定义的,在这里不可见(当然,宏会忽略名称空间)。
您可以通过添加以下内容来编译代码
#undef setbuf
在包含<sstream>
之前。
https://stackoverflow.com/questions/50670001
复制相似问题