开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜