I've been trying to learn ANTLR and get it working with C output code using this tutorial (also referenced in this question). I successfully got ANTLR to generate the lexer and parser as C source, but I cannot get them to compile using gcc on Mac OS X Snow Leopard (i686-apple-darwin10-gcc-4.2.1). Below is the result when I try to compile the "SimpleCalcLexer.c".
dyn-72-33-132-199:Desktop bf$ gcc -o lexer SimpleCalcLexer.c
Undefined symbols:
"_main", referenced from:
start in crt1.10.6.o
"_antlr3LexerNewStream", referenced from:
_SimpleCalcLexerNewSSD in ccjXa6NU.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
The SimpleCalcLexer.c file does not reference "main" anywhere (nor is it defined), but the parser does define it, so I tried to compile that:
dyn-72-33-132-199:Desktop bf$ gcc -o parser SimpleCalcParser.c
Undefined symbols:
"_antlr3CommonTokenStreamSourceNew", referenced from:
_main in ccn8ZVhk.o
"_antlr3ParserNewStream", referenced from:
_SimpleCalcParserNewSSD in ccn8ZVhk.o
"_SimpleCalcLexerNew", referenced from:
_main in ccn8ZVhk.o
"_antlr3AsciiFileStreamNew", referenced from:
_main in ccn8ZVhk.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
So several questions:
1) What am I doing wrong? I'm pretty sure the libraries are being found, as there are other antlr functions and definitions being found in the code. Am I calling gcc incorrectly? (I've never compiled anything this complex on the commandline before.)
2) What is ccn8ZVhk.o
? I can tell that it is an object code file, but I can't find it on my system (both locate
and mdfind
).