Can I compile ANTLR to a binary executable (with GCJ?)?

Helge Hess

  1. get & install gcj and libgcj. Both can be found at:

    gcj is part of the GNU compiler (gcc 2.95.1) and libgcj is a separate library containing the Java runtime system.

  2. delete AWT dependend code (antlr/debug/misc directory)
  3. goto antlr root directory
  4. make the library

    Note that you should compile class files, ICE's may occur when compiling the .java source files (I suppose because of Java 1.1 language features)

    First make a shared library containing antlr classes:
           gcj -shared -fPIC -o  
               `find antlr -name "*.class"`

    This generates a lot of output which can be ignored and hopefully a which can be copied into the LD_LIBRARY_PATH, eg to /usr/local/lib.

    On my Linux host the result is a 2MB shared library which can be stripped ('strip') down to 1.1MB. It may be further reduced by selective compilation of only necessary classes ...

  5. make the cantlr binary
           gcj --main=antlr.Tool antlr/Tool.class 
               -o cantlr 
               -L/usr/local/lib -lantlr

    This should result in a small binary (56K on my host) which just loads the You can copy the binary to /usr/local/bin.

  6. go to examples/java and test cantlr
         cd examples/java
         ../../cantlr java.g

    it should take less than 1s on a P3 host

How to compile antlr generated source with gcj

  1. make as described above
  2. generate your Java stuff as usual, then compile using gcj and libantlr, eg:
           cantlr Grammar.g
           gcj -c -o Lexer.o
           gcj -c -o Parser.o
           gcj -c -o Tokens.o
           gcj -c -o Main.o
           gcj --main=Main -o Main Main.o Lexer.o Parser.o Tokens.o -lantlr
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact