Problem with using a generated file from flex
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 a开发者_JS百科nd 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()'
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
精彩评论