antlr-4.7-cpp-cmake-base icon indicating copy to clipboard operation
antlr-4.7-cpp-cmake-base copied to clipboard

${antlr4cpp_src_files_antlrcpptest} is empty on build

Open gress2 opened this issue 7 years ago • 0 comments

Hello,

Because of some subtleties of CMake, it looks like this variable is actually not set when

add_executable(test_antlr main.cpp ${antlr4cpp_src_files_antlrcpptest}) is called. I think this is due to the fact that this variable is set at build time.

As a result, the linker will not be able to resolve references to TParser, etc. This can be seen with the following main.cpp:

#include <iostream>
#include <antlr4-runtime.h>
#include "TParser.h"

int main() {
  std::cout << "Hello World" << std::endl;
  antlrcpptest::TParser tp(nullptr);
  return 0;
}
CMakeFiles/test_antlr.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x53): undefined reference to `antlrcpptest::TParser::TParser(antlr4::TokenStream*)'
main.cpp:(.text+0x67): undefined reference to `antlrcpptest::TParser::~TParser()'

This seems to only be the case on a fresh build i.e. one where cmake .. has only been done once. The next time cmake is run this variable will be populated, and the build will succeed.

gress2 avatar Jun 08 '18 22:06 gress2