Antlr C运行时中的未定义引用示例

Undefined References In Antlr C Runtime Example

本文关键字:引用 未定义 运行时 Antlr      更新时间:2023-10-16

我有一个问题运行C运行时的例子在http://www.antlr.org/depot/examples-v3/C/treeparser从Antlr

我已经从http://www.antlr.org/download/C下载并安装了C运行时。图书馆图书馆。A位于/usr/local/lib中,antlr头位于/usr/local/include中。这是鹿角图书馆吗?在其他示例中,我看到提到的"antlr3c"库,而我的前面有"lib"。

我下载了示例文件,并将它们放在/home/frazer/examples的一个名为"example"的文件夹中然后让Antlr创建自动生成的解析器和Lexer文件,从那里运行:

gcc *.c -o test -I. -L -llibantlr3c

,它给了我以下错误:

/tmp/ccvXlH3T.o: In function `LangDumpDeclNewSSD':
LangDumpDecl.c:(.text+0x89): undefined reference to `antlr3TreeParserNewStream'
/tmp/cc3TwzKz.o: In function `LangLexerNewSSD':
LangLexer.c:(.text+0xd3): undefined reference to `antlr3LexerNewStream'
/tmp/ccpfbaFf.o: In function `LangParserNewSSD':
LangParser.c:(.text+0x8c): undefined reference to `antlr3ParserNewStream'
LangParser.c:(.text+0xf1): undefined reference to `ANTLR3_TREE_ADAPTORNew'
LangParser.c:(.text+0x103): undefined reference to `antlr3VectorFactoryNew'
/tmp/ccpfbaFf.o: In function `decl':
LangParser.c:(.text+0x6ca): undefined reference to `antlr3RewriteRuleSubtreeStreamNewAE'
LangParser.c:(.text+0x76f): undefined reference to `antlr3RewriteRuleTOKENStreamNewAE'
LangParser.c:(.text+0x811): undefined reference to `antlr3RewriteRuleTOKENStreamNewAE'
LangParser.c:(.text+0x85d): undefined reference to     `antlr3RewriteRuleSubtreeStreamNewAEE'
/tmp/ccED3tJV.o: In function `main':
main.c:(.text+0x46): undefined reference to `antlr3AsciiFileStreamNew'
main.c:(.text+0xe0): undefined reference to `antlr3CommonTokenStreamSourceNew'
main.c:(.text+0x1d0): undefined reference to `antlr3CommonTreeNodeStreamNewTree'
collect2: ld returned 1 exit status

我之前唯一使用Antlr的经验是在Java中,而我之前唯一使用C/c++的经验是在Visual Studio中,所以我对链接和命令行编译等都是新手。所以我猜这是一个非常简单的错误,涉及错误的链接,或者错误的antlr库。

提前道歉和感谢。

您正在使用不带参数的-L选项。选项-llibantlr3c被视为-L的目录参数,而不是要链接的库。因为链接中没有包含antlr库,所以您将获得所有缺失的符号。另外,-l在库名前加上'lib',所以试试

gcc *.c -o test -I. -lantlr3c
如果libantlr3c

。如果文件位于非标准目录中,则使用-L标志添加该目录

在版本3.4之后,请更改为input = antlr3FileStreamNew ((antlr3_uint8)argv[1], ANTLR3_ENC_8BIT);

Not, antlr3AsciiFileStreamNew(argv[1])为例参考中松真司http://www.antlr.org/wiki/display/ANTLR3/Five +分钟+简介+ + ANTLR + 3