문제

  • Downloaded flex-2.5.37.tar.gz
  • Unpacked and followed INSTALL's instructions: ./configure + make + make install
  • In a new folder, I've written a file example.l containing:

    %{
    int a = 0, b = 0;
    %}
    
    %%
    \n   ++a; ++b;
    .    ++b;
    
    %%
    int main()
    {
         yylex();
         printf("%d - %d", a, b);
    }
    

    which is a basic example from their website. Counting lines and characters in a file.

  • In a terminal, I ran flex example.l. It generated lex.yy.c
  • After that:
    - gcc lex.yy.c -o lexyy: Throws undefined symbols for architecture x86_64
    - gcc lex.yy.c -lfl: ld: library not found for -lfl
    - gcc lex.yy.c -ll: Generates a.out, but when I run it against a file, it doesn't work (prints "0 - 0").

    It seems that I can't get this damn file to compile. How does it know where to find the necessary libraries? Shouldn't the linking work from here (this current folder)?

    It's a bit depressing that I can't get the simplest of examples going.

  • 도움이 되었습니까?

    해결책

    Alright. So it turns out I was missing a parameter named %option noyywrap, which goes here:

    %{
    int a = 0, b = 0;
    %}
    
    %option noyywrap
    
    %%
    \n   ++a; ++b;
    .    ++b;
    ...
    

    Apparently this tells FLEX that there's only one source file. So it's not a gcc issue, it was a FLEX config problem.

    Thank you all for taking the time to read the question. Hope this helps anyone else.

    라이센스 : CC-BY-SA ~와 함께 속성
    제휴하지 않습니다 StackOverflow
    scroll top