How do I build my parser in C++?

Peter Wells

Here is a really awesome page of information by Peter Morling on using C++ with ANTLR.

In general, you need to compile all the supplied .cpp files (in the cpp directory), and link them to your project. I recommend building a library.

I use the GNU compiler, g++, on Linux as follows:

      g++ -I. -c *.cpp
      ar r libantlr.a *.o

Or, to build a shared library:

      g++ -fPIC -I. -c *.cpp
      g++ -shared -Wl,-soname,libantlr.so -o libantlr.so *.o

Then, compile the generated .cpp files (and any other source you provide), and link in the ANTLR library:
      g++ -I .../antlr/cpp -c *.cpp
      g++ -o app_name *.o -L .../antlr/cpp -l antlr

On Windows, with MSVC, I build a static library (antlr.lib) from the supplied .cpp files as one project, and link it into subsequent projects which use ANTLR. I believe others have built DLLs of ANTLR, but I haven't tried it.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


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

 

 

About | Sitemap | Contact