[antlr-interest] Antlr-2.7.6 with Visual Studio 8.0

Mike Ventham mike at doublevdesign.co.uk
Wed Mar 15 06:24:20 PST 2006


There was an additional change in config.hpp

# if ( _MSC_VER <= 1400 )
// Supposedly only for MSVC7 and before...
// Not allowed to put 'static const int XXX=20;' in a class definition
#       define NO_STATIC_CONSTS
#       define NO_TEMPLATE_PARTS
# endif

Version 8 is MSC_VER 1400

Apologies for the omission.

At 13:39 15/03/2006, Mark Kattenbelt wrote:
>Hi Mike,
>Thanks for sharing that. I've updated that file, which indeed causes 
>an error when NO_STATIC_CONSTS is defined. Initially I kept trying 
>to compile without NO_STATIC_CONSTS defined (as this shouldn't be a 
>problem for any newish compiler), but this gives a lot of problems 
>when linking. This is because most static const int's are 
>initialized in the class declaration, which I dont think is the 
>correct way. Even with some tweaking there was no way I could get VS 
>to compile antlr without setting NO_STATIC_CONSTS.
>However, with your fix and that define I've managed to make a 
>dynamic library. Hopefully this will work well.
>I do think antlr should be a bit more user friendly towards visual 
>studio users.
>>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 
>>"_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)
>>const size_t TokenStreamRewriteEngine::MIN_TOKEN_INDEX = 0;
>>const int TokenStreamRewriteEngine::PROGRAM_INIT_SIZE = 100;
>>At 10:40 14/03/2006, Mark Kattenbelt wrote:
>>>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"
>>>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 
>>>/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 
>>>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.
>>>Mark Kattenbelt
>>Mike Ventham
>>Chief Technical Consultant
>>Double V Design & Support Services
>>Email : mike at doublevdesign.co.uk

More information about the antlr-interest mailing list