视觉工作室中的 yacc 和 bison
我要将用于 UNIX 的 C 项目移植到 Windows 中。到目前为止,我可以编译它,但不能构建它。我遇到的问题是,头文件中声明的一些函数是在 yacc 文件中定义的。所以我收到以下错误:
error LNK2001: unresolved external symbol function_name
我在项目的源目录中添加 .y 和 .l 文件。我想我无法将 yacc 文件移植到 Windows 版本中,或者我在做一些愚蠢的事情。我在网上搜索它,但无法获得正确的教程。您能让我知道
- 如何在项目。
- 我怎样才能使这些文件与Windows兼容?
- 我如何将它们与其他目标文件链接。
编辑
我尝试使用 flex.exe
将 .l
文件更改为 .yy.c
文件。以下是它的命令
c:\> flex.exe name.l
假设 flex.exe 和 name.l 都在 C;>
中。我加载了所有这些文件 .l .y(之前在 unix 系统中用于解析) .yy.c(适用于 Windows 的相应 yacc 文件)
在先前现有项目的解决方案中。编译后,我得到以下内容
Can't read the header file parserheaderfile.h
这是需要由 unix 中的 bison
生成的头文件 系统。所以我认为我无法使 bison
与 windows
兼容。所以请问我该如何解决这个问题?
提前致谢。
I am going to port the C project that was for unix into windows. So far, I could make it compile but not build . The problem I am getting is , some of the functions which are declared in the header files are defined in the yacc files.so I am getting the following errors:
error LNK2001: unresolved external symbol function_name
I am adding .y and .l files in the source directory of the project.I think I could not port yacc files into windows version or am I doing something stupid.I search it on web but could not get proper tutorial for it.Could you please let me know
- How could I add .y or .l files in the project.
- How would I make those file compatible to the windows?
- How can I link them with other object files.
EDIT
I tried with changing the the .l
files into the .yy.c
files using the flex.exe
.Following is the command for it
c:\> flex.exe name.l
Supposing that both the flex.exe and name.l are in C;>
.And I loaded those all those files .l .y(previously present for parsing in unix system) .yy.c(corrsonding yacc file for windows)
in the solution of previously exisiting project. Once I compile,I get the following
Can't read the header file parserheaderfile.h
This is the header file which needs to be generated by the bison
in the unix
system. So I think I am not able to make the bison
compatible for windows
.So please him me how can I solve this problem?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要为 .y 和 .l 文件添加自定义构建规则。为此,您需要
flex -olexer.c lexer.l
lexer.c
parser.y parser.c
bison -oparser.c parser.y
parser.c parser.h
另外您还需要系统搜索路径中有flex.exe、bison.exe和m4.exe。另一个缺点是 VS 无法正确获取依赖项,因此当您更改解析器或词法分析器文件中的某些内容时,您需要手动重建项目。
You need to add custom build rules for your .y and .l files. To do this, you need to
flex -olexer.c lexer.l
lexer.c
parser.y parser.c
bison -oparser.c parser.y
parser.c parser.h
Also you need to have flex.exe, bison.exe and m4.exe in the system search path. Another drawback is that VS does not get the dependencies right, so when you change something in the parser or lexer files, you need to manually rebuild the project.