Having problems while trying to generate a parser in antlr4

  antlr4, c++

I am trying to compile my own ANTLR4 parser in C++

#include "nibble.h"

using namespace antlr4;
using namespace nibble;

int main(int argc, const char* argv[]){

    const std::string file_name = argv[1];
    ANTLRInputStream input(file_name);

    return 0;
}

but when I compile it by typing g++ nibblec.cpp -o nibblec -I /usr/local/include/antlr4-runtime I get

/usr/bin/ld: /tmp/ccqG8KT4.o: warning: relocation against '_ZTVN6antlr416ANTLRInputStreamE' in read-only section '.text._ZN6antlr416ANTLRInputStreamD2Ev[_ZN6antlr416ANTLRInputStreamD5Ev]'
/usr/bin/ld: /tmp/ccqG8KT4.o: in function 'main':
nibblec.cpp:(.text+0x64): undefined reference to 'antlr4::ANTLRInputStream::ANTLRInputStream(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: /tmp/ccqG8KT4.o: in function 'antlr4::ANTLRInputStream::~ANTLRInputStream()':
nibblec.cpp:(.text._ZN6antlr416ANTLRInputStreamD2Ev[_ZN6antlr416ANTLRInputStreamD5Ev]+0xf): undefined reference to `vtable for antlr4::ANTLRInputStream'
/usr/bin/ld: nibblec.cpp:(.text._ZN6antlr416ANTLRInputStreamD2Ev[_ZN6antlr416ANTLRInputStreamD5Ev]+0x42): undefined reference to 'antlr4::CharStream::~CharStream()'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status

What is ld? And why I get all this warnings? Am I doing something wrong with ANTLR4?

EDIT: I am using ANTLR 4.9.1

Source: Windows Questions C++

LEAVE A COMMENT