antlr4 icon indicating copy to clipboard operation
antlr4 copied to clipboard

CPP compilation error

Open nIxedoahz opened this issue 1 year ago • 3 comments

definition of static data member runtime on clion error

nIxedoahz avatar Jul 08 '22 16:07 nIxedoahz

Please elaborate

KvanTTT avatar Jul 08 '22 16:07 KvanTTT

Please elaborate

Definition of dllimport static field not allowed CommonTokenFactory.cpp:14:50: error: definition of static data member 'antlr4::CommonTokenFactory::DEFAULT' of dllimport'd class  const std::unique_ptr<TokenFactory<CommonToken>> CommonTokenFactory::DEFAULT(new CommonTokenFactory);                                                   ^~~~~~~~~~~~~~~~~~ mingw32-make.exe[3]: *** [CMakeFiles\antlr4-cpp-runtime.dir\build.make:198: CMakeFiles/antlr4-cpp-runtime.dir/src/CommonTokenFactory.cpp.obj] Error 1 mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:84: CMakeFiles/antlr4-cpp-runtime.dir/all] Error 2 mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:117: CMakeFiles/plsql.dir/rule] Error 2 mingw32-make.exe: *** [Makefile:136: plsql] Error 2

nIxedoahz avatar Jul 20 '22 08:07 nIxedoahz

which shell are you using?

with PowerShell 7.3.0-preview.3-189-gbcafe74c174091a0f47cf7a5eeb4bca8aefa8718

$originalPath=$Env:Path
Set-Item -Path Env:Path -Value ("C:\apache\apache-maven-3.8.6\bin;C:\sylvanmats\cnpm;C:\sylvanmats\cnpm\lib;C:\jdk-17.0.1\bin;c:\msys64\mingw64\bin;c:\msys64\usr\bin;c:\cmake-3.22.1-windows-x86_64\bin;C:\Program\ Files\ (x86)\GnuWin32\bin;C:/sylvanmats/cnpm/cpp_modules/openssl;C:/sylvanmats/cnpm/cpp_modules/urlcpp;C:/sylvanmats/cnpm/cpp_modules/zlib/dist/lib;C:/sylvanmats/cnpm/cpp_modules/libgit2/dist/lib;C:/sylvanmats/cnpm/cpp_modules/antlr4/runtime/Cpp/dist;" + $Env:Path)
New-Item alias:cmake -value 'cmake.exe'

cd cpp_modules/antlr4/runtime/Cpp
mkdir -p build
mkdir -p run
cd build
cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../dist -DANTLR_JAR_LOCATION=C:\Users\roger\.cnpm\cpp_modules\antlr4\tool\target\antlr4-4.10.2-SNAPSHOT.jar -DWITH_DEMO=False ..
#mingw32-make.exe -f Makefile clean
New-Item Env:DESTDIR -value 'C:\Users\roger\.cnpm\cpp_modules\antlr4\runtime\Cpp\run'
mingw32-make.exe -j 3 -f Makefile
mingw32-make.exe -j 3 -f Makefile install

makes the libantlr4-runtime.dll. Working on issues after that with building :Utf8Test.cpp

rimmartin avatar Jul 24 '22 22:07 rimmartin

I also met a similar error when compiling antlr4-runtime. But the difference is that I compiled it into DLL on linux using x86_64-w64-mingw32-g++-posix, and the whole error msg is like:

error: definition of static data member ‘antlr4::CommonToken::EMPTY_SOURCE’ of dllimport’d class
   23 | const std::pair<TokenSource*, CharStream*> CommonToken::EMPTY_SOURCE;
      |                                            ^~~~~~~~~~~
make[2]: *** [CMakeFiles/antlr4_static.dir/build.make:167:CMakeFiles/antlr4_static.dir/src/CommonToken.cpp.o]

Thank you for any suggestions!

kumori123 avatar Nov 03 '22 02:11 kumori123

I fixed this error by adding the code #define ANTLR4CPP_STATIC at the top of antlr4-common.h. As mentioned here in the docs, you need to define ANTLR4CPP_STATIC if you are compiling the runtime to make a static lib in order for certain classes to not be defined multiple times, hence the error messages.

Fluxyn avatar Sep 24 '23 23:09 Fluxyn