2012-03-19 101 views
1

我想编译一个简单的语法,我用ANTLR创建的,但我不断收到链接错误。最后,我想将ANTLR语法包含在C++项目中,但现在如果在C中编译和链接,我会很高兴。我第一次尝试:ANTLR语法链接错误

g++ -oX -I/usr/local/include -I../src -L/usr/local/lib -lantlr3c \ 
../src/RtfLexer.cpp \ 
../src/RtfParser.cpp 

然后我尝试:

gcc -oX -lantlr3c -I../src ../src/RtfLexer.cpp ../src/RtfParser.cpp 

,但我不断收到:

/tmp/ccJgJxMH.o: In function `RtfLexerNewSSD': 
RtfLexer.cpp:(.text+0xb0): undefined reference to `antlr3LexerNewStream' 
/tmp/ccVZ2Vco.o: In function `RtfParserNewSSD': 
RtfParser.cpp:(.text+0x7d): undefined reference to `antlr3ParserNewStream' 
RtfParser.cpp:(.text+0xfa): undefined reference to `ANTLR3_TREE_ADAPTORNew' 
RtfParser.cpp:(.text+0x10e): undefined reference to `antlr3VectorFactoryNew' 
/tmp/ccVZ2Vco.o: In function `plaintext(RtfParser_Ctx_struct*)': 
RtfParser.cpp:(.text+0x8c4): undefined reference to `antlr3RewriteRuleTOKENStreamNewAE' 
RtfParser.cpp:(.text+0x992): undefined reference to `antlr3RewriteRuleTOKENStreamNewAE' 
RtfParser.cpp:(.text+0xa60): undefined reference to `antlr3RewriteRuleTOKENStreamNewAE' 
RtfParser.cpp:(.text+0xb2e): undefined reference to `antlr3RewriteRuleTOKENStreamNewAE' 
RtfParser.cpp:(.text+0xbfc): undefined reference to `antlr3RewriteRuleTOKENStreamNewAE' 
[more to follow] 

如此看来,库中无法找到,但G ++和gcc唐抱怨。我重新安装了这个库,重新生成了语法,到目前为止没有运气。我在这里错过了很明显的东西吗 在此先感谢!

回答

2

把库在编译器命令的末尾:

g++ -oX -I../src ../src/RtfLexer.cpp ../src/RtfParser.cpp -lantlr3c 
+1

感谢这么多,不知道! – yvesonline 2012-03-19 13:31:48