Error in MulVAL: multiple definition of `mylval'; collect2: error: ld returned 1 exit status
Error in MulVAL: multiple definition of `mylval'; collect2: error: ld returned 1 exit status
我在 fedora OS 上使用“make”命令编译 MulVAL 时遇到此错误 OS。
这是错误:
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 的经验也不多。除了导致您观察到的编译器错误之外,还有大量问题。
要修复 graphit.l
中的即时错误,请将第 5 行更改为:
extern YYSTYPE* mylval;
我认为这个变量根本不是必需的;在我看来,它像是对某些 Windows DLL 问题的笨拙解决方案。但是删除变量比确保它有一个单一的定义更有效。
我在 fedora OS 上使用“make”命令编译 MulVAL 时遇到此错误 OS。
这是错误:
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 的经验也不多。除了导致您观察到的编译器错误之外,还有大量问题。
要修复 graphit.l
中的即时错误,请将第 5 行更改为:
extern YYSTYPE* mylval;
我认为这个变量根本不是必需的;在我看来,它像是对某些 Windows DLL 问题的笨拙解决方案。但是删除变量比确保它有一个单一的定义更有效。