Re: [Flex-help] undefined reference to `yylex' when compiling as C++
flex is a tool for generating scanners
Brought to you by:
wlestes
From: Filipp B. <b_...@zo...> - 2014-10-08 11:27:20
|
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. |