2011-10-01 32 views
0

我在Antlr的http://www.antlr.org/depot/examples-v3/C/treeparser上运行C运行时示例时出现问题。在Antlr C运行时示例中未定义的引用

我已经从http://www.antlr.org/download/C下载并安装了C运行时。库libantlr3c.a位于/ usr/local/lib中,antlr头文件位于/ usr/local/include中。这是正确的antlr库吗?在其他例子中,我已经看到了“antlr3c”库,而我的“lib”就是infront。

我下载了示例文件,并将它们放置在/ home/fraser/examples中名为“example”的文件夹中。然后,我让ANTLR的创建自动生成的解析器和词法文件,并从那里我运行:

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库。

道歉,并提前致谢。

回答

2

您正在使用不带参数的-L选项。选项-llibantlr3c被视为-L的目录参数,而不是要链接的库。由于antlr库未包含在链接中,因此您将获取所有缺失的符号。此外,-l预规划“LIB”库名称,所以尽量

gcc *.c -o test -I. -lantlr3c 

如果libantlr3c.a文件是在一个非标准的目录,然后用-L标志

+0

谢谢,但现在我越来越: 在/ usr /斌/劳工处:跳绳不兼容的/ usr /local/lib/libantlr3c.so当搜索-lantlr3c/usr/bin/ld时:跳过不兼容的/usr/local/lib/libantlr3c.a搜索-lantlr3c时 /usr/bin/ld:找不到-lantlr3c collect2:ld返回1个退出状态,听起来不错。此外,我无法在此格式化,对不起。 –

+0

这很可能是您的32/64位问题。你有一个32位的操作系统和编译器以及一个64位版本的antlr或者其他方法。为您的系统获取正确的版本。 –

+0

啊,是的,这样做后,运行ldconfig它的作品,谢谢!令人尴尬的简单解决方案:) –

相关问题