Re: [Flex-help] undefined reference to `yylex' when compiling as C++
flex is a tool for generating scanners
Brought to you by:
wlestes
From: Will E. <wes...@gm...> - 2014-10-08 11:37:11
|
Do you have the flex source to hand? There's several c++ examples in the test suite that might be helpful to you. The manual should also have working examples. (I.e. if it doesn't, or if you do what they do and still see the same problem, that's a bug.) On Wednesday, 8 October 2014, 3:25 pm +0400, "Filipp B." <b_...@zo...> wrote: > Which header is that? I tried to include FlexLexer.h but then the > compiler says that I am trying to redefine class. > > > On 08.10.2014 15:03, Will Estes wrote: > > Looks like you need to include the flex c++ header so that you have a c++ lexer function, if I'm reading your example right. > > > > On Wednesday, 8 October 2014, 9:23 am +0400, "Filipp B." <b_...@zo...> wrote: > > > >> Hello. I am just starting with flex and trying to compile a simple > >> program, no bison yet. > >> > >> /* calc.l */ > >> > >> %{ > >> #include <iostream> > >> #include <exception> > >> %} > >> > >> %option debug > >> %option nodefault > >> %option noyywrap > >> %option c++ > >> > >> %% > >> \+ { > >> std::cout << "PLUS" << std::endl; > >> } > >> > >> \* { > >> std::cout << "MULTIPLY" << std::endl; > >> } > >> > >> - { > >> std::cout << "MINUS" << std::endl; > >> } > >> > >> \/ { > >> std::cout << "DIVIDE" << std::endl; > >> } > >> > >> .|\n { > >> std::terminate(); > >> } > >> %% > >> > >> /* calc.l end */ > >> > >> The problem is the following: > >> > >> $ flex calc.l && g++ lex.yy.cc -lfl > >> /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/../../../../lib64/libfl.a(libmain.o): > >> In function `main': > >> libmain.c:(.text.startup+0xb): undefined reference to `yylex' > >> collect2: error: ld returned 1 exit status > >> > >> > >> Writing pure C code using printf instead, with no %option c++, and > >> compiling it with gcc works fine, but this doesn't. Why? > >> > >> -- > >> Filipp B. > >> > >> > >> ------------------------------------------------------------------------------ > >> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer > >> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports > >> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper > >> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer > >> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk > >> -- > >> Flex-help mailing list > >> Fle...@li... > >> https://lists.sourceforge.net/lists/listinfo/flex-help > > -- > Filipp B. > > > ------------------------------------------------------------------------------ > Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer > Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports > Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper > Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer > http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk > -- > Flex-help mailing list > Fle...@li... > https://lists.sourceforge.net/lists/listinfo/flex-help |