2

I write simple flex program and run it in linux with following code

flex filename.l
cc lex.yy.c -lfl
./a.out

but now I want to run it in windows I do orders in following link now I am trying to compile flex file with following commend but it says that cc is not recognized then I try to compile it with following commend

gcc lex.yy.c -lfl

and it says that cannot find -lfl, then I try this

gcc lex.yy.c

but i got a lot of error for example undefined reference to yywrap. what should I do to recognize flex libraries ?

Community
  • 1
  • 1
Karo
  • 273
  • 4
  • 16
  • 2
    Find were your flex library is located. It'll probably be called libfl.so or libfl.a. Then add -L to the line where you compile lex.yy.c. Its basically complaining that it cant find the library. – Paul Rooney Oct 19 '14 at 08:37
  • @PaulRooney I find libfl.a its in "C:\GnuWin32\lib". then tried this commands `gcc lex.yy.c -L"C:\GnuWin32\lib"` and `gcc lex.yy.c -L "C:\GnuWin32\lib"` and `gcc lex.yy.c -L"C:\GnuWin32\lib" -l"libfl.a"` and ... but no one works – Karo Oct 19 '14 at 09:30
  • @PaulRooney I used `gcc lex.yy.c -L"C:\GnuWin32\lib" -lfl` and now it's okay, thank you :D – Karo Oct 19 '14 at 09:34

1 Answers1

4

The issue is that it cant find the library. On linux it would be under /usr/bin or usr/local/bin which are both on the system path. On windows there is no such standard place for libraries.

When you use the -lfl option it will search on the system path for a file called libfl.o (shared library) or libfl.a (static library) and link your binary with this file.

So what you need to do is provide the location of the library using the -L option for gcc.

Your new compile command would therefore be.

gcc lex.yy.c -L<path to library> -lfl
Paul Rooney
  • 20,879
  • 9
  • 40
  • 61