Compiling Antlr2

Compiling Antlr2 with no success. As of this article being written the latest version is 2.7.7.
The source is downloaded and configured but when `make` processing this errors comes in.

>> /usr/bin/make -C lib/cpp/src all                         

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

make[3]: Entering directory `/opt/antlr2/antlr-2.7.7/lib/cpp/src'

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/ANTLRUtil.cpp

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/ASTFactory.cpp

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/ASTNULLType.cpp

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/ASTRefCount.cpp

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/BaseAST.cpp

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/BitSet.cpp

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/CharBuffer.cpp

*** compiling /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/CharScanner.cpp

In file included from /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/CharScanner.cpp:10:0:

/opt/antlr2/antlr-2.7.7/scripts/../lib/cpp/antlr/CharScanner.hpp:474:30: error: ‘EOF’ was not declared in this scope

  static const int EOF_CHAR = EOF;

                              ^

/opt/antlr2/antlr-2.7.7/scripts/../lib/cpp/antlr/CharScanner.hpp: In member function ‘bool antlr::CharScannerLiteralsLess::operator()(const string&, const string&) const’:

/opt/antlr2/antlr-2.7.7/scripts/../lib/cpp/antlr/CharScanner.hpp:565:41: error: ‘strcasecmp’ was not declared in this scope

   return (strcasecmp(x.c_str(),y.c_str())<0 p="">                                         ^



xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

                      >> E R R O R <<

============================================================



g++ -O2 -DNDEBUG -felide-constructors -pipe -c  -I . -I /opt/antlr2/antlr-2.7.7/scripts/../lib/cpp /opt/antlr2/antlr-2.7.7/lib/cpp/src/../../../lib/cpp/src/CharScanner.cpp



============================================================

Got an error while trying to execute  command  above.  Error

messages (if any) must have shown before. The exit code was:

exit(1)

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

make[3]: *** [/opt/antlr2/antlr-2.7.7/lib/cpp/src/CharScanner.o] Error 1

make[3]: Leaving directory `/opt/antlr2/antlr-2.7.7/lib/cpp/src'

make[2]: *** [all] Error 1

make[2]: Leaving directory `/opt/antlr2/antlr-2.7.7/lib/cpp'

make[1]: *** [all] Error 1

make[1]: Leaving directory `/opt/antlr2/antlr-2.7.7/lib'

make: *** [all] Error 1

Includes some headers fixed the problems. Open the CharScanner.cpp and put this at the header.

#include   >fstream<
#include   >strings.h< // before
#include   >antlr/config.hpp<
// and

#include >antlr/exersharedinputstate.hpp< // after
#ifndef EOF
    #define EOF     std::ifstream::traits_type::eof()
#endif

Run `make clean` and the `make; make install`. Compile success, Yeah!

Comments

Anonymous said…
Open CharScanner.hpp not CharScanner.cpp and do the following:

#include
#include // before
#include
// and

#include // after
#ifndef EOF
#define EOF std::ifstream::traits_type::eof()
#endif