[英]dyld: lazy symbol binding failed: Symbol not found: _yylex
I am new to flex and bison, on my Mac, I install flex and bison on my Mac using these:我是 flex 和 bison 的新手,在我的 Mac 上,我使用这些在我的 Mac 上安装 flex 和 bison:
brew install flex && brew link flex --force
brew install bison && brew link bison --force
This is my test1ll.l
file这是我的test1ll.l
文件
%{
#include <iostream>
using namespace std;
%}
%%
[0-9]+ { cout << "Number "; }
[a-zA-Z]+ { cout << "Word "; }
[ \t] ;
%%
then I run the following commands:然后我运行以下命令:
flex -otest1ll.c test1ll.l
g++ test1ll.c -otest1 -lfl
./test1
I got these errors:我收到这些错误:
dyld: lazy symbol binding failed: Symbol not found: _yylex
Referenced from: /usr/local/opt/flex/lib/libfl.2.dylib
Expected in: flat namespace
dyld: Symbol not found: _yylex
Referenced from: /usr/local/opt/flex/lib/libfl.2.dylib
Expected in: flat namespace
Abort trap: 6
Can someone explain and help me fix it?有人可以解释并帮我解决吗?
If you are going to use C++, you will find it easier to make your flex scanner self-contained, rather than relying on libfl
, which presumes C linkage.如果你打算使用 C++,你会发现让你的 flex 扫描器更容易自包含,而不是依赖libfl
,它假定 C 链接。
Add %option noyywrap
before the first %%
(but see below) to avoid the need for yywrap
and add a simple main
at the end, after the second %%
:在第一个%%
之前添加%option noyywrap
(但见下文)以避免需要yywrap
并在最后添加一个简单的main
,在第二个%%
之后:
int main() {
while (yylex()) {}
return 0;
}
Personally I prefer:我个人更喜欢:
%option noinput nounput noyywrap nodefault
The first two options make it possible to compile with -Wall
if you don't use input()
or unput()
and the last one will cause flex to complain if your scanner does not recognise some input.如果您不使用input()
或unput()
,前两个选项可以使用-Wall
进行编译,如果您的扫描仪无法识别某些输入,最后一个选项将导致 flex 抱怨。 In this case, it would have flagged the fact that your scanner fails to act on non-alphanumeric characters, just echoing them to standard out.在这种情况下,它会标记出您的扫描仪无法对非字母数字字符执行操作,只是将它们回显到标准输出。 (But perhaps that was intentional.) (但也许这是故意的。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.