0

I want to integrate my grammar in antlr4 with llvm to generate llvm IR. I make the example code(Kaleidoscope\Chapter3) in llvm into a antlr program.

Standalone llvm example or antlr4 cpp runtime program works both OK.

My environment: Windows, visual studio 2019, Debug , (Debug DLL in antlr4-runtime, compiled from source.)

However I got the following error message:

Not clue how to fix it.

Severity    Code    Description File    Project Line    Suppression State
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: virtual struct antlrcpp::Any __cdecl antlr4::tree::AbstractParseTreeVisitor::visit(class antlr4::tree::ParseTree *)" (__imp_?visit@AbstractParseTreeVisitor@tree@antlr4@@UEAA?AUAny@antlrcpp@@PEAVParseTree@23@@Z) referenced in function "void __cdecl work3(void)" (?work3@@YAXXZ)  examples\Kaleidoscope\Chapter3_2\antlr_try.obj  Kaleidoscope-Ch3_2  1   

Link command:

1>Target Link:
1>  Using "Link" task from assembly "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.Build.CppTasks.Common.dll".
1>  Task "Link"
1>    All source files are not up-to-date: missing command TLog "W:\ubuntu\llvm7_build\examples\Kaleidoscope\Chapter3_2\Kaleidoscope-Ch3_2.dir\Debug\Kaleidos.BE9FF897.tlog\link.command.1.tlog".
1>    Environment Variables passed to tool:
1>      VS_UNICODE_OUTPUT=1812
1>    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\bin\HostX64\x64\link.exe /ERRORREPORT:PROMPT /OUT:"W:\ubuntu\llvm7_build\Debug\bin\Kaleidoscope-Ch3_2.exe" /INCREMENTAL /NOLOGO "antlr4-runtime.lib" ..\..\..\Debug\lib\LLVMCore.lib ..\..\..\Debug\lib\LLVMSupport.lib ..\..\..\Debug\lib\LLVMBinaryFormat.lib psapi.lib shell32.lib ole32.lib uuid.lib advapi32.lib ..\..\..\Debug\lib\LLVMDemangle.lib kernel32.lib user32.lib gdi32.lib winspool.lib oleaut32.lib comdlg32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"W:/ubuntu/llvm7_build/Debug/bin/Kaleidoscope-Ch3.pdb" /SUBSYSTEM:CONSOLE /STACK:"10000000" /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"W:/ubuntu/llvm7_build/Debug/lib/Kaleidoscope-Ch3.lib" /MACHINE:X64  /machine:x64 "Kaleidoscope-Ch3_2.dir\Debug\windows_version_resource.res"
1>    "Kaleidoscope-Ch3_2.dir\Debug\antlr_try.obj"
1>    "Kaleidoscope-Ch3_2.dir\Debug\asts.obj"
1>    "Kaleidoscope-Ch3_2.dir\Debug\EvalVisitor.obj"
1>    "Kaleidoscope-Ch3_2.dir\Debug\myllvmBaseVisitor.obj"
1>    "Kaleidoscope-Ch3_2.dir\Debug\myllvmLexer.obj"
1>    "Kaleidoscope-Ch3_2.dir\Debug\myllvmParser.obj"
1>    "Kaleidoscope-Ch3_2.dir\Debug\myllvmVisitor.obj"
1>    "Kaleidoscope-Ch3_2.dir\Debug\toy.obj"
1>    Tracking command:
1>    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Tracker.exe /a /d "C:\Program Files (x86)\MSBuild\15.0\FileTracker\FileTracker32.dll" /i W:\ubuntu\llvm7_build\examples\Kaleidoscope\Chapter3_2\Kaleidoscope-Ch3_2.dir\Debug\Kaleidos.BE9FF897.tlog /r "W:\UBUNTU\LLVM7_BUILD\EXAMPLES\KALEIDOSCOPE\CHAPTER3_2\KALEIDOSCOPE-CH3_2.DIR\DEBUG\ANTLR_TRY.OBJ|W:\UBUNTU\LLVM7_BUILD\EXAMPLES\KALEIDOSCOPE\CHAPTER3_2\KALEIDOSCOPE-CH3_2.DIR\DEBUG\ASTS.OBJ|W:\UBUNTU\LLVM7_BUILD\EXAMPLES\KALEIDOSCOPE\CHAPTER3_2\KALEIDOSCOPE-CH3_2.DIR\DEBUG\EVALVISITOR.OBJ|W:\UBUNTU\LLVM7_BUILD\EXAMPLES\KALEIDOSCOPE\CHAPTER3_2\KALEIDOSCOPE-CH3_2.DIR\DEBUG\MYLLVMBASEVISITOR.OBJ|W:\UBUNTU\LLVM7_BUILD\EXAMPLES\KALEIDOSCOPE\CHAPTER3_2\KALEIDOSCOPE-CH3_2.DIR\DEBUG\MYLLVMLEXER.OBJ|W:\UBUNTU\LLVM7_BUILD\EXAMPLES\KALEIDOSCOPE\CHAPTER3_2\KALEIDOSCOPE-CH3_2.DIR\DEBUG\MYLLVMPARSER.OBJ|W:\UBUNTU\LLVM7_BUILD\EXAMPLES\KALEIDOSCOPE\CHAPTER3_2\KALEIDOSCOPE-CH3_2.DIR\DEBUG\MYLLVMVISITOR.OBJ|W:\UBUNTU\LLVM7_BUILD\EXAMPLES\KALEIDOSCOPE\CHAPTER3_2\KALEIDOSCOPE-CH3_2.DIR\DEBUG\TOY.OBJ|W:\UBUNTU\LLVM7_BUILD\EXAMPLES\KALEIDOSCOPE\CHAPTER3_2\KALEIDOSCOPE-CH3_2.DIR\DEBUG\WINDOWS_VERSION_RESOURCE.RES" /b MSBuildConsole_CancelEvent1847db8bdd10464784fa77f132d003d1  /c "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\bin\HostX64\x64\link.exe"  /ERRORREPORT:PROMPT /OUT:"W:\ubuntu\llvm7_build\Debug\bin\Kaleidoscope-Ch3_2.exe" /INCREMENTAL /NOLOGO "antlr4-runtime.lib" ..\..\..\Debug\lib\LLVMCore.lib ..\..\..\Debug\lib\LLVMSupport.lib ..\..\..\Debug\lib\LLVMBinaryFormat.lib psapi.lib shell32.lib ole32.lib uuid.lib advapi32.lib ..\..\..\Debug\lib\LLVMDemangle.lib kernel32.lib user32.lib gdi32.lib winspool.lib oleaut32.lib comdlg32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"W:/ubuntu/llvm7_build/Debug/bin/Kaleidoscope-Ch3.pdb" /SUBSYSTEM:CONSOLE /STACK:"10000000" /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"W:/ubuntu/llvm7_build/Debug/lib/Kaleidoscope-Ch3.lib" /MACHINE:X64  /machine:x64 "Kaleidoscope-Ch3_2.dir\Debug\windows_version_resource.res"
1>    "Kaleidoscope-Ch3_2.dir\Debug\antlr_try.obj"
1>    "Kaleidoscope-Ch3_2.dir\Debug\asts.obj"
1>    "Kaleidoscope-Ch3_2.dir\Debug\EvalVisitor.obj"
1>    "Kaleidoscope-Ch3_2.dir\Debug\myllvmBaseVisitor.obj"
1>    "Kaleidoscope-Ch3_2.dir\Debug\myllvmLexer.obj"
1>    "Kaleidoscope-Ch3_2.dir\Debug\myllvmParser.obj"
1>    "Kaleidoscope-Ch3_2.dir\Debug\myllvmVisitor.obj"
1>    "Kaleidoscope-Ch3_2.dir\Debug\toy.obj"
worldterminator
  • 2,968
  • 6
  • 33
  • 52
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Botje Nov 26 '19 at 11:58
  • Did you add the antlr runtime DLL to your link instructions? – Botje Nov 26 '19 at 11:58
  • @Botje No. like I said, it is exactly the same program, except I compiled it in llvm projectm adding compiler flags the same as other llvm examples. Yes, I add DLL. – worldterminator Nov 26 '19 at 12:17
  • What do you mean by "add DLL"? Please add a screenshot of your linker configuration or commandline proving that you are linking with the antlr runtime. – Botje Nov 26 '19 at 12:19
  • link log attached – worldterminator Nov 26 '19 at 13:00
  • Next step: Is that symbol present in antlr4-runtime.lib? The implementation is visible in the [header](https://github.com/antlr/antlr4/blob/master/runtime/Cpp/runtime/src/tree/AbstractParseTreeVisitor.h) – Botje Nov 26 '19 at 13:19
  • I didn't find the command line contains -I. But the header contains `tree/AbstractParseTreeVisitor.h`, I guess since it pass the compile step, but fails at linker step. So I can assume the include path is configured properly? – worldterminator Nov 26 '19 at 13:54
  • I meant to check the contents of the `.lib` file to see if that symbol is present. – Botje Nov 26 '19 at 14:24
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/203108/discussion-between-worldterminator-and-botje). – worldterminator Nov 26 '19 at 14:28

0 Answers0