2011-10-01 34 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它的作品,謝謝!令人尷尬的簡單解決方案:) –

相關問題