Note that there are some explanatory texts on larger screens.

plurals
  1. POCompiling an ANTLR 3 grammar in C
    text
    copied!<p>I've been trying to learn ANTLR and get it working with C output code using <a href="http://www.antlr.org/wiki/display/ANTLR3/Five+minute+introduction+to+ANTLR+3" rel="nofollow noreferrer">this</a> tutorial (also referenced in <a href="https://stackoverflow.com/questions/637338/how-to-use-the-grammar-files-generated-by-antlr">this</a> 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". </p> <pre><code>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 </code></pre> <p>The SimpleCalcLexer.c file does not reference "main" anywhere (nor is it defined), but the parser <em>does</em> define it, so I tried to compile that:</p> <pre><code>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 </code></pre> <p>So several questions:<br> 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.)<br> 2) What is <code>ccn8ZVhk.o</code>? I can tell that it is an object code file, but I can't find it on my system (both <code>locate</code> and <code>mdfind</code>). </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload