0

I am using C library antlr3c. I installed the library using: sudo apt-get install libantlr3c-dev

#include "antlr3defs.h"
..

string DBparser::sparqlParser(const string& _sparql, SPARQLquery& _sparql_query)
{
    pANTLR3_INPUT_STREAM input;
    pSparqlLexer lex;
    pANTLR3_COMMON_TOKEN_STREAM tokens;
    pSparqlParser parser;
    input = antlr3StringStreamNew((ANTLR3_UINT8 *)(_sparql.c_str()),ANTLR3_ENC_UTF8,_sparql.length(),(ANTLR3_UINT8 *)"QueryString");
}

When I run the program containing the above fragment I get the error: NetBeansProjects/gstore/Parser/DBparser.cpp:25: undefined reference to `antlr3StringStreamNew'

I am not getting how to resolve this error as antlr3StringStreamNew is indeed declared in antlr3defs.h. Although I am unable to find its definition.

If this related to incompatibility with version 3.4 of antlr3c (as I have installed version 3.2). If this is indeed the case then, is there any alternate function in antlr3c version 3.4 by which I may achieve the same functionality.

Jannat Arora
  • 2,759
  • 8
  • 44
  • 70
  • 1
    How do you build your program? – user58697 Oct 15 '14 at 23:19
  • 7
    I'm skeptical that you get that error when you *run* the program; it looks more like a linker error. Update your question to show us how you built the program. You probably just need to add a `-l...` option when you build, so the linker knows where to find the library that defines `antlr3StringStreamNew`. You might also need to do something to allow for the fact that you're calling a function in a C library from C++ code; does `antlr3defs.h` have the required `extern "C"`? – Keith Thompson Oct 15 '14 at 23:24
  • @Keith Actually this feature has got changed from 3.2 to 3.4 as is evident from a user response at https://theantlrguy.atlassian.net/wiki/display/ANTLR3/Five+minute+introduction+to+ANTLR+3 – Jannat Arora Oct 15 '14 at 23:42

1 Answers1

1

Keith is right - the linker you are using is expecting different symbols due to C++ name mangling. Thus, though your code will compile, at the link stage it fails with that error.

If you surround your header include like so, the linker should find the symbols:

extern "C" {
    #include "antlr3defs.h"
}

The result is that your code compiles with references to C-style function names, allowing the linker to match them up with corresponding symbols in the object files of the antlr3 library.

Chris McGrath
  • 1,936
  • 16
  • 17