无法编译flex&野牛(找不到符号x86_64) [英] Can't compile flex & bison (Symbols not found x86_64)
问题描述
我正在尝试在Flex& amp;上编译一个简单的程序.运行优胜美地的Mac上的野牛,但出现以下错误:
I am trying to compile a simple program on Flex & Bison on my Mac running Yosemite but get the following error:
体系结构x86_64的未定义符号: "_yyerror",引用自: pr1-19c182.o中的_yyparse ld:找不到架构x86_64的符号 clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)
Undefined symbols for architecture x86_64: "_yyerror", referenced from: _yyparse in pr1-19c182.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
我的两个文件看起来像这样,它们在我老师的Ubuntu安装中编译,但是我无法在Mac上运行它们:
My two files look like this, they compile on my teacher's Ubuntu installation but I can't get them to work on my Mac:
pr1.y
%{
#include <stdio.h>
%}
%%
expr : expr '+' term {printf(" + ");}
| term
;
term : term '*' fact {printf(" * ");}
| fact
;
fact : "(" expr ")"
| '0' {printf("0");}
| '1' {printf("1");}
| '2' {printf("2");}
| '3' {printf("3");}
| '4' {printf("4");}
| '5' {printf("5");}
| '6' {printf("6");}
| '7' {printf("7");}
| '8' {printf("8");}
| '9' {printf("9");}
%%
pr1.l
%{
#include "pr1.tab.h"
%}
%%
[0-9] {return (yytext[0]);}
[+*()] {return (yytext[0]);}
\n {return (0);}
. {}
%%
我使用以下命令编译所有内容:
I compile everything using the following commands:
bison -d pr1.y
flex pr1.l
gcc -o result lex.yy.c pr1.tab.c -lfl -std=gnu89
我使用-std标志的原因是因为默认值是c99,而flex和bison生成的代码会得到警告和错误.有什么想法吗?
The reason I use the -std flag is because the default is c99 and the code generated by flex and bison gets warnings and errors. Any ideas???
推荐答案
您需要在野牛输入文件(pr1.y
)中定义yyerror
.并且您需要声明yylex
否则您将收到另一个警告.
You need to define yyerror
in your bison input file (pr1.y
). And you need to declare yylex
or you will get another warning.
以下内容会很好:
%{
#include <stdio.h>
void yyerror(const char* msg) {
fprintf(stderr, "%s\n", msg);
}
int yylex();
%}
我不知道没有老师的机器怎么工作.
I have no idea how it works without that on your teacher's machine.
此外,Mac OS X具有非常老的bison和flex版本.您可能要升级.
Also, Mac OS X has very old versions of bison and flex. You might want to upgrade.
这篇关于无法编译flex&野牛(找不到符号x86_64)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!