warning: relocation against `_ZTVN6antlr417CommonTokenStreamE' in read-only section `.text._ZN6antlr417CommonTokenStreamD2Ev[_ZN6antlr417CommonTokenStreamD5Ev]'

1,157 views
Skip to first unread message

Muhammed Baldeh

unread,
Nov 5, 2021, 8:31:14 AM11/5/21
to antlr-discussion
Antlr4 was recommended to me by Federico.

I love it, but becoming frustrating because I am unable to build the runtime on C++.

I am also relatively new in C++ and find it challenging to have a grip of CMake.

This is the repo of the project I am using the lib in https://github.com/alagiesellu/cpp_calculator_project  with Antlr4 added. 

I successfully generated a C++ parser code from the Calculator grammar in the repo. 

I am using CLion IDE.

Here is the output of the build fail;

====================[ Build | cpp_calculator_project | Debug ]==================
/var/lib/snapd/snap/clion/169/bin/cmake/linux/bin/cmake --build /home/leber/CLionProjects/cpp_calculator_project/cmake-build-debug --target cpp_calculator_project -- -j 6
-- Configuring done
-- Generating done
-- Build files have been written to: /home/leber/CLionProjects/cpp_calculator_project/cmake-build-debug
[ 50%] Linking CXX executable cpp_calculator_project
/usr/bin/ld: CMakeFiles/cpp_calculator_project.dir/main.cpp.o: warning: relocation against `_ZTVN6antlr417CommonTokenStreamE' in read-only section `.text._ZN6antlr417CommonTokenStreamD2Ev[_ZN6antlr417CommonTokenStreamD5Ev]'
/usr/bin/ld: CMakeFiles/cpp_calculator_project.dir/main.cpp.o: in function `engine(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
/home/leber/CLionProjects/cpp_calculator_project/main.cpp:11: undefined reference to `antlr4::ANTLRInputStream::ANTLRInputStream(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: /home/leber/CLionProjects/cpp_calculator_project/main.cpp:14: undefined reference to `CalculatorLexer::CalculatorLexer(antlr4::CharStream*)'
/usr/bin/ld: /home/leber/CLionProjects/cpp_calculator_project/main.cpp:17: undefined reference to `antlr4::CommonTokenStream::CommonTokenStream(antlr4::TokenSource*)'
/usr/bin/ld: /home/leber/CLionProjects/cpp_calculator_project/main.cpp:20: undefined reference to `CalculatorParser::CalculatorParser(antlr4::TokenStream*)'
/usr/bin/ld: /home/leber/CLionProjects/cpp_calculator_project/main.cpp:23: undefined reference to `CalculatorParser::expression()'
/usr/bin/ld: /home/leber/CLionProjects/cpp_calculator_project/main.cpp:24: undefined reference to `CalculatorParser::~CalculatorParser()'
/usr/bin/ld: /home/leber/CLionProjects/cpp_calculator_project/main.cpp:24: undefined reference to `CalculatorLexer::~CalculatorLexer()'
/usr/bin/ld: /home/leber/CLionProjects/cpp_calculator_project/main.cpp:24: undefined reference to `CalculatorParser::~CalculatorParser()'
/usr/bin/ld: /home/leber/CLionProjects/cpp_calculator_project/main.cpp:24: undefined reference to `CalculatorLexer::~CalculatorLexer()'
/usr/bin/ld: CMakeFiles/cpp_calculator_project.dir/main.cpp.o: in function `antlr4::ANTLRInputStream::~ANTLRInputStream()':
/home/leber/CLionProjects/cpp_calculator_project/libs/antlr4-runtime/runtime/src/ANTLRInputStream.h:15: undefined reference to `vtable for antlr4::ANTLRInputStream'
/usr/bin/ld: /home/leber/CLionProjects/cpp_calculator_project/libs/antlr4-runtime/runtime/src/ANTLRInputStream.h:15: undefined reference to `antlr4::CharStream::~CharStream()'
/usr/bin/ld: CMakeFiles/cpp_calculator_project.dir/main.cpp.o: in function `antlr4::BufferedTokenStream::~BufferedTokenStream()':
/home/leber/CLionProjects/cpp_calculator_project/libs/antlr4-runtime/runtime/src/BufferedTokenStream.h:24: undefined reference to `vtable for antlr4::BufferedTokenStream'
/usr/bin/ld: /home/leber/CLionProjects/cpp_calculator_project/libs/antlr4-runtime/runtime/src/BufferedTokenStream.h:24: undefined reference to `antlr4::TokenStream::~TokenStream()'
/usr/bin/ld: CMakeFiles/cpp_calculator_project.dir/main.cpp.o: in function `antlr4::CommonTokenStream::~CommonTokenStream()':
/home/leber/CLionProjects/cpp_calculator_project/libs/antlr4-runtime/runtime/src/CommonTokenStream.h:36: undefined reference to `vtable for antlr4::CommonTokenStream'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/cpp_calculator_project.dir/build.make:93: cpp_calculator_project] Error 1
make[2]: *** [CMakeFiles/Makefile2:83: CMakeFiles/cpp_calculator_project.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/cpp_calculator_project.dir/rule] Error 2
make: *** [Makefile:124: cpp_calculator_project] Error 2

Mike Lischke

unread,
Nov 5, 2021, 9:30:44 AM11/5/21
to ANTLR discussion group
Hi Muhammed,

Being new to C++ and to CMake and to ANTLR is quite a challenge. The error you see is a linker error. Your calculator project obviously doesn't link to the compiled ANTLR4 lib.

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/antlr-discussion/c142316f-1803-4e7d-bdbc-3e938ef3a96an%40googlegroups.com.





Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages