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

John Williams jr.williams at tiscali.co.uk
Tue Sep 6 14:03:32 PDT 2005


Mark Kattenbelt wrote:

> 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
>
>
At Ric Klaren's suggestion in this thread I downloaded the sources 
provided for cygwin users on the download page and then rebuilt the 
antlr/libraries.  My problems have now disappeared and I can use antlr 
to generate parsers using C++ and JAVA. I was using the cygwin binaries 
downloaded off antlr's download site. As Ric says, they must have been 
generated using an older version of gcc. I have not yet tried mingw but 
will try it soon.

The only steps I followed using cygwin  were:

1. Install the antlr sources for cygwin
2. Run the "configure" script
   (./configure --with-cxx=g++ --enable-java --enable-cxx)
3. Do a "make install"
   (make install)

I'm not sure if the configure options are required but it worked OK.

John


More information about the antlr-interest mailing list