简体   繁体   English

MulVAL 中的错误:`mylval' 的多重定义; collect2: 错误: ld 返回 1 个退出状态

[英]Error in MulVAL: multiple definition of `mylval'; collect2: error: ld returned 1 exit status

I'm getting this error while compiling MulVAL with "make" command on fedora OS.在 Fedora OS 上使用“make”命令编译 MulVAL 时出现此错误。

This is the error:这是错误:

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

This is the Makefile I'm compiling:这是我正在编译的 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

...

First few lines of graphit.y (showing where mylval is used): graphit.y 的前几行(显示使用 mylval 的位置):

#define YYSTYPE char *
    extern YYSTYPE yylval;
    extern "C"
    {
        int yyparse(void);
        int yylex(void);
        YYSTYPE* mylval = &yylval;
       int yywrap()
       {
           return 1;
       }
    }

Few lines of graphit.l (also showing where mylval is used):几行 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;
...
%%

The full code can be found at https://github.com/fiware-cybercaptor/mulval完整代码可以在https://github.com/fiware-cybercaptor/mulval找到

I tried to modify the graphit.y file by removing the YYSTYPE* before the mylval like this:我试图通过删除 mylval 之前的 YYSTYPE*​​ 来修改 graphit.y 文件,如下所示:

 mylval = &yylval;

but it gave this error:但它给出了这个错误:

mylval does not name a type

which means that it's not defined before.这意味着它之前没有定义。

Please can anyone help?请问有人可以帮忙吗?

I gather that you didn't write the program you're trying to compile, and I see that you filed some sort of bug report.我认为您没有编写您要编译的程序,而且我看到您提交了某种错误报告。

It's also evident that whoever did write the program had very little or no experience with flex or bison, and not much with C either.同样明显的是,编写程序的人几乎没有或没有使用 flex 或 bison 的经验,对 C 的经验也不多。 There are a great number of problems beyond the one which creates the compiler error you observed.除了导致您观察到的编译器错误的问题之外,还有很多问题。

To fix the immediate error in graphit.l , change line 5 to:要修复graphit.l的即时错误, graphit.l第 5 行更改为:

extern YYSTYPE* mylval;

I don't believe that the variable is necessary at all;我根本不相信这个变量是必要的; it looks to me like a clumsy solution to some Windows DLL problem.在我看来,它就像是针对某些 Windows DLL 问题的笨拙解决方案。 But removing the variable is more work than just making sure it has a single definition.但是删除变量不仅仅是确保它有一个单一的定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM