Fix: /usr/bin/ld: cannot find -ly collect2: error: ld returned 1 exit status

Fix: /usr/bin/ld: cannot find -ly collect2: error: ld returned 1 exit status

我无法编译 yacc i lex:

$ cc gramatyka.c gramatyka.h semantyka.c -ly -ll 

输出错误:

/usr/bin/ld: cannot find -ly collect2: error: ld returned 1 exit status

如何解决?

很可能您在 LDFLAGS 中遗漏了 -L path/to/dir/with/liby(如果 liby 在同一文件夹中,只需在 -ly 之前添加 -L.)。

您收到此错误的原因是因为编译器无法 link 此库。如果您不确定此库的默认位置,请使用“-L”选项添加完整路径。