开发者

Undefined References In Antlr C Runtime Example

开发者 https://www.devze.com 2023-04-10 15:25 出处:网络
I\'m having a problem running the C runtime example at http://www.antlr.org/depot/examples-v3/C/treeparser from Antlr.

I'm having a problem running the C runtime example at http://www.antlr.org/depot/examples-v3/C/treeparser from Antlr.

I've downloaded and installed the C runtime from http://www.antlr.org/download/C. The library libantlr3c.a is located in /usr/local/lib, and the antlr 开发者_StackOverflowheaders are located in /usr/local/include. Is this the right antlr library? In other examples I've seen the "antlr3c" library mentioned, whereas mine has the "lib" infront.

I downloaded the example files and placed them in a folder named "example" in /home/fraser/examples. Then I let Antlr create the auto-generated Parser and Lexer files, and from there I run:

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

and it gives me the following errors:

/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

My only previous experience with Antlr was in Java, and my only prior C/C++ experience has been with Visual Studio, so I'm new to linkages and command-line compilation, etc. So I'm guessing this is a very simple error involving the wrong linkages, or the wrong antlr library.

Apologies and thanks in advance.


You are using the -L option without a parameter. The option -llibantlr3c is being treated like the directory parameter of -L instead of a library to link. Because the antlr library isn't being included in the link, you are getting all the missing symbols. Also, -l prepends 'lib' to the library name, so try

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

If libantlr3c.a file is in a nonstandard directory, then add that directory with the -L flag


After ver 3.4, Pls, change to input = antlr3FileStreamNew ((pANTLR3_UINT8)argv[1], ANTLR3_ENC_8BIT);

Not, antlr3AsciiFileStreamNew(argv[1]) as examples refer Shinji Nakamatsu http://www.antlr.org/wiki/display/ANTLR3/Five+minute+introduction+to+ANTLR+3

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号