简体   繁体   English

dyld:惰性符号绑定失败:找不到符号:_yylex

[英]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.

相关问题 dyld:惰性符号绑定失败,opencv - dyld: lazy symbol binding failed, opencv 在Mac上编译C ++代码时处理“ dyld:惰性符号绑定失败:找不到符号”错误 - Handling “dyld: lazy symbol binding failed: Symbol not found” error when compiling C++ code on Mac OSX 10.7.5上的node-gyp - dyld:惰性符号绑定失败:找不到符号 - node-gyp on OSX 10.7.5 — dyld: lazy symbol binding failed: Symbol not found dyld:懒惰的符号绑定失败:找不到符号。 预期在:平面命名空间 - dyld: lazy symbol binding failed: Symbol not found. Expected in: flat namespace 惰性符号绑定失败:找不到符号 - Lazy symbol binding failed: symbol not found dyld:懒惰的符号绑定失败:找不到符号:__ZN5boost11this_thread5hiden11sleep_untilERK8timespec(具有…6hidden11sleep_untilERK8timespec) - dyld: lazy symbol binding failed: Symbol not found: __ZN5boost11this_thread5hiden11sleep_untilERK8timespec (have …6hidden11sleep_untilERK8timespec) 找不到Dyld符号错误 - Dyld Symbol not Found Error 链接C ++动态库时,延迟符号绑定失败 - Lazy symbol binding failed when linking C++ dynamic library dyld:找不到符号:_PyBaseObject_Type - dyld: Symbol not found: _PyBaseObject_Type 未找到dyld符号,但nm报告否则(OS X更新问题) - dyld symbol not found, but nm reports otherwise (OS X Update issue)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM