Problem with using a generated file from flex

别来无恙 提交于 2020-01-05 03:18:21

问题


I am trying to setup a project that uses flex (fast lex, not the adobe one). I am running on Ubuntu and I installed flex via the apt-get method.

I have googled the compile error and I have either found people who just create their own patches around it or a lot of forums where people ask and nobody answers.

This is my .ll file

%option c++

%%

%%

It generates a lex.yy.cc file which I include in my main file.

#include "lex.yy.cc"

int main ()
{
    return 0;
}

The error I get are a lot of "multiple definition" errors like this.

lex.yy.cc | 511 | multiple definition of `yyFlexLexer::yylex() ' |

I am pretty stuck, the flex version is 2.5.35 and I am using the gcc compiler through the code::blocks editor.

If I compile the main file straight through the terminal. I get this.

undefined reference to `yyFlexLexer::yywrap()'


回答1:


Found the problem! You should not include the generated file but compile it and include it as an object file.

flex file.ll 
g++ -c lex.yy.cc 
g++ -o main main.cpp lex.yy.o


来源:https://stackoverflow.com/questions/7285818/problem-with-using-a-generated-file-from-flex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!