1

In my compilers class we are writting Flex/Lex code. When I compiled the .l file and tried to compile the resultant lex.yy.c file with gcc, I got the following error:

Undefined symbols for architecture arm64:
  "_yywrap", referenced from:
      _yylex in lex-fb85c9.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Does is posible to compile it in a Apple Silicon (M1) Mac, at least in a Linux VM?

rici
  • 234,347
  • 28
  • 237
  • 341
Christian Leyva
  • 133
  • 2
  • 10
  • Does this help? https://stackoverflow.com/questions/1811125/undefined-reference-to-yywrap – Steve Friedl Sep 22 '22 at 15:54
  • 1
    @SteveFriedl's link is a reasonable duplicate except that on a default flex install on macOS, you would need to use `-ll` rather than `-lfl`. `%option noyywrap` is a better solution. – rici Sep 22 '22 at 16:37
  • Yes sorry, I have been busy these weeks and I haven't seen the answers before. The @rici solution and yours worked fine. Thanks! – Christian Leyva Oct 19 '22 at 02:11

1 Answers1

1

I created a test file and compiled:

% flex lex.l
% cc -o lex lex.yy.c -lc -ll
% grep 'yylex();' lex.yy.c
    yylex();

The -ll on the cc command links against the libl library. Current M1 based macOS does not provide a libfl library you may see referenced.

James Risner
  • 5,451
  • 11
  • 25
  • 47