yvesonline
yvesonline

Reputation: 4837

ANTLR grammar linking error

I'm trying to compile a simple grammar which I created with ANTLR but I keep getting linking errors. In the end I want to include the ANTLR grammar in a C++ project, but for now I would be happy if compiling and linking in C works. I first tried:

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

Then I tried:

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

but I keep getting:

/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]

So it seems that the library can not be found, but g++ and gcc don't complain. I re-installed the library, re-generated the grammar, no luck so far. Am I missing something obvious here? Thanks in advance!

Upvotes: 1

Views: 726

Answers (1)

hmjd
hmjd

Reputation: 121971

Put the libraries at the end of the compiler command:

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

Upvotes: 2

Related Questions