[英]How to include Yacc/Bison-Parser into own project?
I'd like to use the yacc/bison parser for my own project. 我想为自己的项目使用yacc / bison解析器。 When building the Parser with my own Makefile, everything works fine.
使用我自己的Makefile构建解析器时,一切正常。 I took the sources from http://ymorin.is-a-geek.org/projects/kconfig-frontends (just the parser that's:
/<path-to-kconfig>/libs/parser
. 我从http://ymorin.is-a-geek.org/projects/kconfig-frontends (只是解析器为
/<path-to-kconfig>/libs/parser
。
Now when including these files into the C++ project in Eclipse, after hitting make, the compiler crashes at the .y
file, because of a syntax error - wasn't able to read the .y - syntax. 现在,当将这些文件包含到Eclipse中的C ++项目中时,在点击make之后,由于语法错误,编译器在
.y
文件处崩溃-无法读取.y-语法。 So I excluded the parser from the building process. 因此,我从构建过程中排除了解析器。
In the answer of Yacc and Lex inclusion confusion , I've read that only the .h files have to be included, to use the functions of the parser. 在回答Yacc和Lex包含混淆时 ,我读到只有.h文件必须包含在内,才能使用解析器的功能。
So what I did is: 所以我所做的是:
void testout(char *txt) {printf(txt);}
void testout(char *txt) {printf(txt);}
void testout(char *txt);
void testout(char *txt);
创建了yconf.h void testout(char *txt);
the main, where I'd like to call the function looks like: 主要,我想在其中调用该函数的样子:
#include "y.tab.h" #include "yconf.h" #include <stdio.h> extern "C"{ int main(int argc, char *argv[]) { char configIn[] = "test"; printf(configIn); testout(configIn); return 0; } }
The error 错误
And now when compiling, an error appears: undefined reference to 'testout(char*)'
. 现在在编译时出现错误:
undefined reference to 'testout(char*)'
。 But Eclipse itself can resolve the function - when clicking that function, the yconf.h opens. 但是Eclipse本身可以解析该功能-单击该功能时,yconf.h将打开。 And that's why I don't know where exactly the problem is.
这就是为什么我不知道问题出在哪里的原因。
Eclipse Settings: Eclipse设置:
In /project/properties/C/C++ Build/Settings I put the same include paths to the parser-sources for gcc
and g++
and the linker. 在/ project / properties / C / C ++ Build / Settings中,我将相同的include路径放置到
gcc
和g++
的解析器源以及链接器中。 Additionally I added in this settings as "Include files" the y.tab.h
and the yconf.h
另外,我在此设置中将
y.tab.h
和yconf.h
添加为“包含文件”
If more information are needed, please ask. 如果需要更多信息,请询问。
I appreciate any advises about how to solve this problem. 感谢您提供有关如何解决此问题的建议。 Thanks for the support
感谢您的支持
Kind Regards 亲切的问候
Okay one really just need the y.tab.h
and y.tab.c
. 好一个真正的刚需
y.tab.h
和y.tab.c
。 That is created with this makefile: 使用此makefile创建的:
lex ./lconf.l
bison -d -y ./yconf.y
My error was: I was programming in C++ and I had the extern "C"
command at the wrong place, that header file needs to be declared as c format. 我的错误是:我使用C ++进行编程,并且在错误的位置输入了
extern "C"
命令,该头文件需要声明为c格式。 Here's the right code: 这是正确的代码:
extern "C"{
#include "y.tab.h"
}
int main(int argc, char *argv[])
{
char configIn[] = "test";
testout(configIn);
return 0;
}
(testout is a function in y.tab.h/c with a simple printf
of the parameter configIn - when executing "test" was printed.) (TESTOUT是在y.tab.h / C的函数用一个简单
printf
参数configIn的-执行“试验”打印时)。
BTW: I excluded all source files of the parser for compilation but of the y.tab.c
BTW:我排除的解析器的所有源文件编译不过的
y.tab.c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.