[antlr-interest] Compiling antlr's generated c++ code

Mark Kattenbelt mark.kattenbelt at gmail.com
Wed Aug 24 10:55:14 PDT 2005


Hello,

I've used antlr for java-based projects before, and that seemed to work 
just fine. Now I want to use it for parsing stuff in a c++ based 
projects, and I am having problems linking the code.

I am using dev-c++ 4.9.9.2 with min-gw (gcc version 3.4.2). I compile 
with all include files from antlr 2.7.5 and with the libantlr.a in the 
library directory. I also include the -lantlr option. The result is that 
it compiles fine, but the linking stage goes totally wrong:

g++.exe src/color.o src/fonts.o src/gameframework.o src/graphics.o 
src/menu.o src/observer.o src/win.o src/widget.o src/GFWLexer.o 
src/GFWParser.o GameFramework_private.res -o "GameFramework.exe" 
-L"C:/Dev-Cpp/lib" -L"D:/Programming/C++/GameFramework/lib" -mwindows 
-lopengl32 -lantlr  -march=athlon-xp -mmmx

D:/Programming/C++/GameFramework/lib/libantlr.a(RecognitionException.o)(.text+0xaa):RecognitionException.cpp: 
undefined reference to `std::string::_S_empty_rep_storage'
D:/Programming/C++/GameFramework/lib/libantlr.a(RecognitionException.o)(.text+0xb4):RecognitionException.cpp: 
undefined reference to `std::string::_S_empty_rep_storage'
D:/Programming/C++/GameFramework/lib/libantlr.a(RecognitionException.o)(.text+0x1ea):RecognitionException.cpp: 
undefined reference to `std::string::_S_empty_rep_storage'

I cannot seem to understand why, perhaps any of you have had the same 
troubles? My parser/lexer definition is the following (it's only a 
start, as I have not even been able to compile this yet, I know its no 
good yet):

header
{
      ANTLR_USING_NAMESPACE(std)
      ANTLR_USING_NAMESPACE(antlr)
}

options
{
    language="Cpp";
    namespaceStd="std";       
    namespaceAntlr="antlr";
}

class GFWParser extends Parser;

options
{
    k = 2;
    exportVocab=GFW;
}

mesh
  : vertices faces
  ;

vertices
  : TAG_START VERTICES TAG_END
    (vertice)*
    TAG_START VERTICES SLASH TAG_END
  ;
 
vertice
  : TAG_START INTEGER TAG_END
    COLON
    TAG_START NUMBER COMMA NUMBER COMMA NUMBER SLASH TAG_END     
  ;
 
faces
  : TAG_START FACES TAG_END
    (face)*
    TAG_START FACES SLASH TAG_END
  ;
 
face
  : TAG_START INTEGER TAG_END
    COLON
    TAG_START NUMBER COMMA NUMBER COMMA NUMBER (COMMA NUMBER)? SLASH 
TAG_END     
  ;

class GFWLexer extends Lexer;

options
{
    k = 2;
    exportVocab=GFW;
}

tokens
{
    VERTICES    = "GVERTICES";
    FACES       = "FACES";
}
                      
WS_     :       (' '
        |       '\t'
        |       '\n'
        |       '\r')
                { _ttype = ANTLR_USE_NAMESPACE(antlr)Token::SKIP; }
        ;
 
NUMBER  : ('0'..'9')+ PERIOD ('0'..'9')*
        ;

PERIOD options { paraphrase = "."; }
        : '.'
        ;

COMMA options { paraphrase = ","; }
        : ','
        ;

COLON options { paraphrase = ":"; }
        : ':'
        ;
       
TAG_START options { paraphrase = "["; }
        : '['
        ;
       
TAG_END options { paraphrase = "]"; }
        : ']'
        ;

SLASH options { paraphrase = "/"; }
        : '/'
        ;

Any help is appreciated!

Cheers,

Mark


More information about the antlr-interest mailing list