jGuru
Register Email     Password Forgot your
password?
HOME FAQS FORUMS DOWNLOADS ARTICLES PEERSCOPE LEARN

  Search   jGuru Search Help

Question Can I compile ANTLR to a binary executable (with GCJ?)?
Topics Tools:ANTLR
Author Helge Hess
Created Sep 3, 1999


Answer
  1. get & install gcj and libgcj. Both can be found at:
             http://sourceware.cygnus.com/java/download.html
    

    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 libantlr.so 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 libantlr.so  \
               --CLASSPATH=".:/usr/local/share/libgcj.zip" \
               `find antlr -name "*.class"`
    

    This generates a lot of output which can be ignored and hopefully a libantlr.so 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 libantlr.so') 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 \
               --CLASSPATH=".:/usr/local/share/libgcj.zip" \
               -o cantlr \
               -L/usr/local/lib -lantlr
    

    This should result in a small binary (56K on my host) which just loads the libantlr.so. 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 libantlr.so 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  Lexer.java
           gcj -c -o Parser.o Parser.java
           gcj -c -o Tokens.o Tokens.java
           gcj -c -o Main.o   Main.java
           gcj --main=Main -o Main Main.o Lexer.o Parser.o Tokens.o -lantlr
    


Is this item helpful?  yes  no     Previous votes   Yes: 0  No: 0



Comments and alternative answers

Comment on this FAQ entry

There are currently no comments

Ask A Question



 
Related Links

ANTLR FAQ

ANTLR Forum

Download now!

Resources

Documentation

Book in progress

ANTLR Consulting

Wish List
Features
About jGuru
Contact Us

 



The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers