Open rea-yseop opened 3 years ago
I have the same problem.
antlr4::ANTLRInputStream inputStream("........");
Using string literal directly also have link error.
undefined reference to `antlr4::ANTLRInputStream::ANTLRInputStream(std::basic_string_view<char, std::char_traits<char> >)'
GCC version: 9.3
Compile flag: --std=c++2a
I simplly changed CMakeLists.txt
in cpp runtime.
# Initialize CXXFLAGS.
if("${CMAKE_VERSION}" VERSION_GREATER 3.1.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++2a")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++2a")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -std=c++2a")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++2a")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -std=c++2a")
endif()
The problem solved. But I'm not sure shall we change it to C++ 20 directly.
@nburles @mike-lischke
C++20 is not an option currently. The runtime compiles with C++17 enabled (I use it like that in one of my projects). But we can target C++20 for the next ANTLR4 release.
Thanks for the answers. But i also had to change the CMakeLists.txt
directly for C++17. Did i miss an option to enable C++17 easily ?
No, the current cmake file is probably still that from the beginning with C++11. I just wanted to say that I already tested the runtime with C++17 and it compiled without problems from what I remember. So it would require a change for C++17 in the cmake files.
Ok thanks. I also tried with C++17 so i can confirm it works. Unfortunately i am using Conan so i can't really edit the file manually or change the flags so it would be nice to enable C++17 in the next version.
Actually i ran into another error after using C++17. Don't know if I should create another issue for that though
For now, I just removed the const
for the members and it works.
A patch has been merged recently for this exact problem.
I think that MSVC needs: if (MSVC) add_compile_options(/Zc:__cplusplus) endif()
To report the correct c++ version
https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170
I updated antlr to 4.9 and I am using the cpp version. My problem seems to be related to https://github.com/antlr/antlr4/pull/2847 where the constructor has been changed.
I have the following code
Which returns
I went to check to symbols of the lib and i only had
I am using c++20 for my project but from https://github.com/antlr/antlr4/blob/4.9/runtime/Cpp/CMakeLists.txt
It looks like we are using c++11. Not sure if this is because of that since we need the string_view from c++17.