SuzLy
SuzLy

Reputation: 133

Compiling simple token identifier using flex

I have a basic lex file:

%{

/* Declarations section */
#include <stdio.h>
void showToken(char *);

%}

%option yylineno
%option noyywrap
digit           ([0-9])
whitespace      ([\t\n ])

%%

{digit}+                    showToken("number");
{whitespace}                ;
.       printf("Lex doesn't know what that is!\n");

%%

void showToken(char * name)
{
     printf("Lex found: %s, %s", name, yytext);
}

I've installed gcc and flex. I compile the following commands:

flex example.lex
gcc -ll lex.yy.c

but i get the error:

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

what am I missing?

Upvotes: 0

Views: 270

Answers (2)

SuzLy
SuzLy

Reputation: 133

The answer for me was to explictly write "gcc -L"C:\GnuWin32\lib" -lfl lex.yy.c".

Upvotes: 0

phlogratos
phlogratos

Reputation: 13924

To use the flex library you need to provide -lfl instead of -ll.

flex example.lex
gcc -lfl lex.yy.c

-ll only works if you're using the original lex command and its library. cygwin contains only flex, the free gnu version.

Upvotes: 2

Related Questions