我正在尝试编译使用ANTLR创建的简单语法,但是我一直在获取链接错误。最后,我想将ANTLR语法包含在C++项目中,但是现在,如果在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不会抱怨。我重新安装了库,重新生成了语法,到目前为止没有运气。我在这里错过明显的东西吗?
提前致谢!

最佳答案

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

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

关于c++ - ANTLR语法链接错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9770138/

10-10 14:02
查看更多