问题描述
在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
这意味着它以前没有定义。
任何人都可以帮忙吗?
解决方法
我发现您没有编写要尝试编译的程序,并且发现您提交了某种错误报告。
很明显,编写该程序的人很少或根本没有flex或bison的经验,也没有C的经验。除了会引起您观察到的编译器错误的问题之外,还有很多问题。
要解决loadImage()
中的立即错误,请将第5行更改为:
Ghost
我根本不认为该变量是必需的。在我看来,它似乎是对某些Windows DLL问题的笨拙解决方案。但是,删除变量比仅仅确保其具有单个定义要耗费更多的工作。