ANTLR语法链接错误

时间:2012-03-19 12:24:00

标签: c++ g++ antlr antlr3

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

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不会抱怨。我重新安装了库,重新生成了语法,到目前为止没有运气。我错过了一些明显的东西吗? 提前谢谢!

1 个答案:

答案 0 :(得分:2)

将库放在编译器命令的末尾:

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