[antlr-interest] VC++ and ANTLR--a Howto (sort of)

jsrs701 jsrs701 at yahoo.com
Wed Dec 12 12:44:39 PST 2001


Hi gang,

After a few-month sojourn to design and construct the virtual machine 
for my little ANTLR project (a prototype-based, C-flavored scripting 
language), I'm back to working in ANTLR proper.  Whoo hoo!  
Unfortunately, as some of you may remember, my project is a VC++ 
project.  I say unfortunately because getting ANTLR and VC++ to be 
friends can be a United Nations-class peacekeeping effort.

Recently I was approached for some help in getting ANTLR to coexist 
peacefully with Visual C++.  Below is what I wrote back.

Some caveats:
* This is for Visual C++ 6.0.  Use At Your Own Risk for other 
versions.  (I think 4.0 doesn't have all the C++ language elements 
you need for Ric's code, so do yerselves a favor and score a copy of 
6.)
* The files that I mention in there can be found in the Files section 
of this list's website (http://groups.yahoo.com/group/antlr-
interest).  There you will find a zip file called "antlr_calc.zip".  
The full URL to that file is http://groups.yahoo.com/group/antlr-
interest/files/antlr_calc.zip.
* Using my libantlr project files, be warned that the debug version 
of the ANTLR lib weighs in at a whopping 2.8MB!

And on with the show...

---------------------------------------------------------

I could never get the VC++ files included in the ANTLR
distributions to work, so I made my own.

By the way, all of these instructions are for VC++
6.0.  I have no idea how they work in other versions.

First of all, put libantlr.dsw and libantlr.dsp
(attachments to this email) into your
\antlr-2.7.1\lib\cpp directory.  Open up libantlr.dsw,
and then do a Batch Build from the Build menu to build
both the Debug and Release versions.

These project files output .lib files (not DLL's!), so
they must be statically linked in the calc project.
(We'll get there in a minute.)  The debug version of
the ANTLR library ends up as
\antlr-2.7.1\lib\cpp\libantrld.lib, and the release
version ends up as \lib\cpp\libantlr.lib.

When you compile the ANTLR library, you will likely
get 4 warnings.  Ignore them--it'll work okay.

Now for the calc project!

Start by creating a new workspace project for a Win32
console program called calc.  Make sure it's saved to
the \antlr-2.7.1\examples\cpp\calc directory.

Add both the Main.cpp and calc.g files to the new
project.  VC++ won't have a clue how to handle calc.g
yet.

First, let's add the ANTLR library to the project.  Go
the Project Settings (Project menu), click on the calc
project at the top of the tree, and make sure it says
"Win32 Debug".  Now click on the Link tab, and in the
Object/library modules box, add
"\antlr-2.7.1\lib\cpp\libantlrd.lib" (without the
quotes) to the beginning.  Now change the Settings For
drop-down to "Win32 Release", and add
"\antlr-2.7.1\lib\cpp\libantlr.lib" to the same box.
You've just added the ANTLR library to the project.

Leave that window open, because now we have to tell
the project where the include files are for ANTLR!

Click on the "calc" entry at the top of the project
tree in the Project Settings window, and then select
"All Configurations" under the Settings For dropdown
on the left.  Then click on the C/C++ tab.  Select
"Preprocessor" under the Category dropdown.

Now, under "Additional include directories", add
"\antlr-2.7.1\lib\cpp" without the quotes.  Now click
OK.

Getting the .g files to compile without any problems
when you do a build is a tricky one, but it can be
done.

First, right-click on the calc.g file in the project
view, and click Settings.  Now select "All
Configurations" from the Settings For drop-down on the
project window.  Now click on the Custom Build tab.

Type something in for the description, like
"Performing Custom Build Step on $(InputPath)".

Under Commands, type:
java antlr.Tool -o $(InputDir) $(InputPath)

Under Outputs, you have to put in the name of every
file that ANTLR will generate from the .g file!  So,
for the calc project, the list will be:
CalcLexer.cpp
CalcLexer.hpp
CalcParser.cpp
CalcParser.hpp
CalcParserTokenTypes.hpp
CalcTreeWalker.cpp
CalcTreeWalker.hpp

Click OK.

Now right-click on calc.g in the Project view, and
select "Compile calc.g".  You should get a message
that it's compiling, and then get zero errors.

Now all those .cpp and .hpp files are there!  So add
them to the project!  Click on the Project menu, "Add
to Project", then "Files", and select all the .cpp and
.hpp files.  (You'll have to change the "Files of
type" dropdown to "All Files" to see the .hpp files.)

And after all that work, you're all done!  Doing a
Rebuild All will cause everything to be recompiled,
including calc.g.

Yahoo won't let me attach more than 3 files, so I'll
email my calc.dsp and calc.dsw files after this.  Just
drop them in the \antlr-2.7.1\examples\cpp\calc
directory.

After all that, you'll probably think strongly about
just doing it all on Unix using make!  :-)  I usually
work in Cygwin now, just so I can use make on Windows
ANTLR projects.

---------------------------------------------------------


Hope this helps.  Terry, I can't remember if anything like this ever 
got added anywhere to the FAQ.  If not, should I post it?

JSRS


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list