[antlr-interest] Antlr-2.7.6 with Visual Studio 8.0 (Again)

Mark Kattenbelt mark.kattenbelt at gmail.com
Thu Mar 16 05:00:18 PST 2006


Hi Mike and others,

At least I wasn't the only one experiencing that problem then. By the 
looks of it you compile your assembly with /MDd, a multi-threaded debug 
library. If I compile with this setting, and link to any project (al be 
it an example) I get a whole lot of run-time errors.

In particular I get a problem when I use the 
TokenStreamRecognitionConstructor(RecognitionException& re) constructor, 
I get heap corruptions as soon as the result of re.getMessage() is 
called. I would like to know if ever someone experienced the same 
problems and recognizes my mistakes.

Even the examples fail. If I compile (against multi-threaded debug for 
both the antlr library and the project) calc then the same problem 
occurs (the stack):

 ...
     operator new(unsigned int size=0x0012f0ac)    C++
     std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 >::_Eos(unsigned int _Newsize=0x0012f300)    C++
     std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 >::assign(const 
std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 
_Right=<Bad Ptr>, unsigned int _Roff=0x0040b76a, unsigned int 
_Count=0x00344818)    C++
     0012fad0   
     std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 >::assign(const 
std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 
_Right=<Bad Ptr>, unsigned int _Roff=0x0012f2e4, unsigned int 
_Count=0x0012f2b8)    C++
     std::allocator<char>::deallocate(char * _Ptr=0x00344888, unsigned 
int __formal=0x00000020)    C++
     std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 >::_Tidy(bool _Built=true, unsigned int _Newsize=0x00000000)    C++
     std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 >::~basic_string<char,std::char_traits<char>,std::allocator<char> 
 >()    C++
 >    
antlr::TokenStreamRecognitionException::TokenStreamRecognitionException(antlr::RecognitionException 
& re={...})    C++
     CalcLexer::nextToken()    C++
     antlr::TokenBuffer::fill(unsigned int amount=0x00000001)    C++
     antlr::TokenBuffer::LT(unsigned int i=0x00000001)    C++
     antlr::LLkParser::LT(unsigned int i=0x00000001)    C++
     CalcParser::atom()    C++
     CalcParser::mexpr()    C++
     CalcParser::expr()    C++
     main(int argc=0x00000001, char * * argv=0x00363380)    C++
     __tmainCRTStartup()    C
     7c816d4f   
     7c8399f3   

A simple program like the following already gives this type of error:

int main()
{
        antlr::NoViableAltForCharException a(1, "blah", 1, 1);
        throw antlr::TokenStreamRecognitionException(a);
}

I presume antlr itself is free of such bugs, but I do not understand 
where I go wrong.

If anyone could shed light on this this would be greatly appreciated.

Cheers,

Mark




>
>
> If it is any help, I built a static library (.lib) using 2.7.6 with 
> the command line.
>
> /Od /I "C:\Development\antlr\antlr-2.7.6\lib\cpp\\" /D "WIN32" /D 
> "_DEBUG" /D "_LIB" /D "_CRT_SECURE_NO_DEPRECATE" /D 
> "_VC80_UPGRADE=0x0600" /D "_MBCS" /FD /EHsc /RTC1 /MDd /Zc:wchar_t- 
> /Zc:forScope- /GR- /Fp".\Debug/antlr_lib.pch" /Fo".\Debug/" 
> /Fd".\Debug/" /FR".\Debug\\" /W3 /nologo /c /Z7 /errorReport:prompt
>
> There is a change in TokenStreamRewriteEngine.cpp (already submitted 
> to Ter)
>
> #ifndef NO_STATIC_CONSTS
> const size_t TokenStreamRewriteEngine::MIN_TOKEN_INDEX = 0;
> const int TokenStreamRewriteEngine::PROGRAM_INIT_SIZE = 100;
> #endif
>
>
> At 10:40 14/03/2006, Mark Kattenbelt wrote:
>> Hello,
>>
>> I've been trying to compile a dll of antlr 2.7.6 in Visual Studio 
>> 2005, so far unsuccessfully.
>> In mingw, I manage to compile it fine, only took a few minutes to set 
>> up! I use the following settings for VS:
>>
>> Include dir: "lib\cpp"
>> Preprocessor: WIN32;_DEBUG;_WINDOWS;_USRDLL;ANTLR_EXPORTS
>> Run-time library: Multi-treaded debug.
>> Create precompiled headers: yes.
>> Function level linking: yes.
>> RTTI: yes.
>>
>> Which results into compiling with the following line:
>>
>> /O2 /I "lib\cpp" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D 
>> "ANTLR_EXPORTS" /D "_WINDLL" /FD /EHsc /MTd /Gy /Yc 
>> /Fp"Debug\antlr-2.7.6.pch" /Fo"Debug\\" /Fd"Debug\vc80.pdb" /nologo 
>> /c /TP /errorReport:prompt
>>
>> And linking with:
>>
>> /OUT:"d:\Fmt\antlr-2.7.6\Debug\antlr-2.7.6.dll" /NOLOGO /DLL 
>> /MANIFEST /MANIFESTFILE:"Debug\antlr-2.7.6.dll.intermediate.manifest" 
>> /ASSEMBLYDEBUG /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib 
>> winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib 
>> oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
>>
>> Now this fails during the linking stage, in particular it keeps 
>> finding symbols that are defined in multiple places:
>>
>> ASTFactory.obj : error LNK2005: "class std::basic_istream<char,struct 
>> std::char_traits<char> > & __cdecl antlr::eatwhite(class 
>> std::basic_istream<char,struct std::char_traits<char> > &)" 
>> (?eatwhite at antlr@@YAAAV?$basic_istream at DU?$char_traits at D@std@@@std@@AAV23@@Z) 
>> already defined in ANTLRUtil.obj
>> ASTFactory.obj : error LNK2005: "class std::basic_string<char,struct 
>> std::char_traits<char>,class std::allocator<char> > __cdecl 
>> antlr::read_string(class std::basic_istream<char,struct 
>> std::char_traits<char> > &)" ...
>>
>> I have tried to compile without precompiled headers, because I do not 
>> see the need for them, this results in:
>>
>> MismatchedCharException.obj : error LNK2005: "public: static int 
>> const antlr::MismatchedCharException::CHAR" 
>> (?CHAR at MismatchedCharException@antlr@@2HB) already defined in 
>> CharScanner.obj
>> MismatchedCharException.obj : error LNK2005: "public: static int 
>> const antlr::MismatchedCharException::NOT_CHAR" 
>> (?NOT_CHAR at MismatchedCharException@antlr@@2HB) already defined in 
>> CharScanner.obj
>> MismatchedCharException.obj : error LNK2005: "public: static int 
>> const antlr::MismatchedCharException::RANGE" 
>> (?RANGE at MismatchedCharException@antlr@@2HB) already defined in 
>> CharScanner.obj
>>
>> Clearly I am doing something wrong, and the settings need tweaking. 
>> Has anyone here managed to build antlr (2.7.6?) with Visual Studio 
>> (8.0?). If so could you please share your settings? Any help is 
>> appreciated.
>>
>> Also, trying to compile it into a static library does not offer any 
>> relief, the errors still persist.
>>
>> Cheers,
>>
>> Mark Kattenbelt
>>
>>
>>
>
>
> Regards
>
> Mike
>
>
> Mike Ventham
> Chief Technical Consultant
> Double V Design & Support Services
> Email : mike at doublevdesign.co.uk
>
>
>



More information about the antlr-interest mailing list