【发布时间】:2021-02-01 12:10:28
【问题描述】:
我在 Fedora 操作系统上使用“make”命令编译 MulVAL 时遇到此错误。
这是错误:
multiple definition of `mylval'; lex.yy.o:/home/user/Desktop/mulval/src/attack_graph/graphit.l:5: first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:4: attack_graph] Error 1
这是我正在编译的 Makefile:
default: install
attack_graph: attack_graph.cpp attack_graph.h Queue.h lex.yy.o y.tab.cpp
g++ -g -DLINUX -Wno-deprecated lex.yy.o y.tab.cpp attack_graph.cpp -o
attack_graph
lex.yy.c: graphit.l
lex -olex.yy.c graphit.l
lex.yy.o: lex.yy.c y.tab.cpp.h
gcc -g -c lex.yy.c -o lex.yy.o
y.tab.cpp y.tab.cpp.h: graphit.y attack_graph.h
bison -dv graphit.y
mv graphit.tab.c y.tab.cpp
mv graphit.tab.h y.tab.cpp.h
...
graphit.y 的前几行(显示 mylval 的使用位置):
#define YYSTYPE char *
extern YYSTYPE yylval;
extern "C"
{
int yyparse(void);
int yylex(void);
YYSTYPE* mylval = &yylval;
int yywrap()
{
return 1;
}
}
graphit.l 的几行(也显示了 mylval 的使用位置):
%{
#include <stdio.h>
#include "y.tab.cpp.h"
#define YYSTYPE char *
YYSTYPE* mylval;
FILE **my_ptr = &yyin;
%}
%%
...
[0-9]*\.[0-9]+ *mylval=(char *)strdup(yytext); return FLOAT;
[\.\[\]\,\(\)] return (int) yytext[0];
[\/a-zA-Z0-9_\-\+\.\=\\]+ *mylval=(char *)strdup(yytext); return ATOM;
...
%%
完整代码见https://github.com/fiware-cybercaptor/mulval
我尝试通过删除 mylval 之前的 YYSTYPE* 来修改 graphit.y 文件,如下所示:
mylval = &yylval;
但它给出了这个错误:
mylval does not name a type
表示之前没有定义。
有人可以帮忙吗?
【问题讨论】:
-
检查生成的代码并找到定义该对象的多个位置,以及原因,然后简单地相应地修复代码。
-
这个“mylval”变量的唯一定义和使用在上面发布的graphit.y和graphit.l中。
-
不,这些被复制到由 bison 和 lex 生成的
.c和.h文件中。这是您的 C++ 编译器实际编译的内容,而不是.y和.l文件。通过检查生成的.c和.h文件以及您的编译指令,重复的符号定义应该很明显。在最坏的情况下,使用objdump来查找哪些对象模块拥有它们,然后逆向工作。 -
好的,我去看看,谢谢
-
@sam:多重定义一目了然,无需查看生成的代码。两个组件都有一个用外部链接定义的
mylval。
标签: c++ c linux makefile fedora