[antlr-interest] Problem linking C++ generated parser

Mark Kattenbelt mark.kattenbelt at gmail.com
Tue Sep 6 10:39:43 PDT 2005


John Williams wrote:

> I have a requirement to build a parser in both Java and C++ under 
> Windows and Linux and Antlr 2.7.5 seems to be the answer. My first 
> attempts have been in Windows 2000, the generated Java is fine. My 
> problem is the generated C++ source files. Compilation is fine but 
> linking is the problem. I have tried cygwin, mingw and Visual C++ (V6) 
> but all cases I am encountering linker problems. It was suggested by 
> Sohail Somani in replying to my first post that I include the errors.
>
> Below are the commands I used with cygwin in attempting to 
> compile/link the C++ generated by antlr. The source grammar was the 
> "calc" example supplied with antlr.
>
> antlr calc.g
> g++ -c *.cpp
> g++ -o calc.exe Main.o CalcLexer.o CalcParser.o CalcTreeWalker.o 
> -lantlr -lstdc++
>
> The linking produced many "undefined" errors, to many to include here 
> so I've abstracted a few of them.
>
> undefined reference to `std::basic_string<char, 
> std::char_traits<char>, std::allocator<char> >::_S_empty_rep_storage'
> undefined reference to `std::__default_alloc_template<true, 
> 0>::allocate(unsigned int)'
> undefined reference to `std::__default_alloc_template<true, 
> 0>::deallocate(void*, unsigned int)'
> undefined reference to `std::__default_alloc_template<true, 
> 0>::allocate(unsigned int)'
> undefined reference to `std::__default_alloc_template<true, 
> 0>::deallocate(void*, unsigned int)'
> undefined reference to `std::basic_string<char, 
> std::char_traits<char>, std::allocator<char> >::_S_empty_rep_storage'
> undefined reference to `std::__default_alloc_template<true, 
> 0>::deallocate(void*, unsigned int)'
> undefined reference to `std::__default_alloc_template<true, 
> 0>::allocate(unsigned int)'
> undefined reference to `std::__default_alloc_template<true, 
> 0>::deallocate(void*, unsigned int)'
> undefined reference to `std::basic_string<char, 
> std::char_traits<char>, std::allocator<char> >::_S_empty_rep_storage'
> undefined reference to `std::__default_alloc_template<true, 
> 0>::deallocate(void*, unsigned int)'
> undefined reference to `std::basic_string<char, 
> std::char_traits<char>, std::allocator<char> >::_S_empty_rep_storage'
> undefined reference to `std::__default_alloc_template<true, 
> 0>::allocate(unsigned int)'
> undefined reference to `std::__default_alloc_template<true, 
> 0>::deallocate(void*, unsigned int)'
>
> They were generated by object modules in 
> "/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libantlr.a". Can anyone 
> suggest what I am doing wrong?
>
> Thanks for any help
>
> John
>
I get pretty much the same errors when building in mingw (via dev-cpp) I 
cannot seem to build the library in the same program, but have managed 
in another mingw install, though a slightly different version.

If you manage to solve it perhaps you could help me out with explaining 
how, or if someone knows a step by step guide of how to build antlr 
solutions in dev-cpp that would be lovely too.

Cheers,

Mark



More information about the antlr-interest mailing list