Search code examples
gcccygwinldyacclex

cannot find -ll collect2: error: ld returned 1 exit status


I got a similar error when I tried to compile my lex.yy.c file generated from lex helloworld.l using gcc lex.yy.c -ll in cygwin.

The helloworld.l contains

%%
[0-9]+ { printf("saw an integer:%s\n", yytext);}
[a-z]+ { printf("saw a lowercase character:%s\n", yytext);}
[A-Z]+ { printf("saw an uppercase character:%s\n", yytext);}
.|\n ;
%%

The output for gcc lex.yy.c -ll was

/usr/lib/gcc/i686-pc-cygwin/10/../../../../i686-pc-cygwin/bin/ld: cannot find -ll
collect2: error: ld returned 1 exit status

Please help me resolve this error and get this to work. Thank you!


Solution

  • as mentioned by @rici

    $ gcc lex.yy.c -lfl
    
    $ ./a < helloworld.l
    saw an integer:0
    saw an integer:9
    saw a lowercase character:printf
    saw a lowercase character:saw
    ...
    

    Why ? The program lexbelongs to the flexpackage and the import library is libfl.a

    $ cygcheck -f /usr/bin/lex
    flex-2.6.4-2
    
    $ cygcheck -l flex | grep a$
    /usr/lib/libfl.a