Using [Flex] on OS X

If you are trying to use flex and you get the following error:

Undefined symbols for architecture x86_64:
  "_yywrap", referenced from:
      _yylex in cceJ8DuJ.o
      _input in cceJ8DuJ.o
ld: symbol(s) not found for architecture x86_64

You need to link with libfl.a. Apparently, OSX does not have libfl.a. Use libl.a instead.

$ gcc lex.yy.c -o flexout -ll

Or create a symlink

$ cd /usr/lib
$ ln -s libl.a libfl.a

4 comments:

Unknown said...

The path for the libraries is sometimes `/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/lib/` I don't know why this happens.

ptdecker said...

This was so helpful. Thank you

ptdecker said...

Very helpful! Thank you.

Unknown said...

Thank you Franklin, this was so helpul!!