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

John Williams jr.williams at tiscali.co.uk
Sun Sep 4 15:58:56 PDT 2005


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


More information about the antlr-interest mailing list