Linker error and syntax warnings when building clang 19.1.5 on Windows

Actually I’m trying to build clazy by the KDE project. For that I need a build of clang.

I followed the instructions described here: GitHub - KDE/clazy: Qt-oriented static code analyzer based on the Clang framework

I cloned the llvm-project repo and checked out the tag llvmorg-19.1.5. For the build I’m using Visual Studio 2022. I have Python 3.12 installed on the build system. I run my build in a Developer Command Prompt for VS 2022.

I used the following command to configure and generate the makefiles for clang:

cmake -DCMAKE_INSTALL_PREFIX=D:\ws\llvm-install\ -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_BUILD_TYPE=Release -G "Ninja" ..\llvm-project

While building I have to issues.

Since I’m using Python 3.12, I got a lot of SyntaxWarnings from llvm\utils\extract_symbols.py, e.g.:

D:\ws\llvm-project\llvm\utils\extract_symbols.py:172: SyntaxWarning: invalid escape sequence '\d'
  match = re.match("(\d+)(.+)", arg)

But more importantely, I got a linker error when the library CTTestTidyModule.dll is getting linked:

[4642/4734] Linking CXX shared module bin\CTTestTidyModule.dll
FAILED: bin/CTTestTidyModule.dll
C:\WINDOWS\system32\cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_dll --intdir=tools\clang\tools\extra\test\CMakeFiles\CTTestTidyModule.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100203~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100203~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MICROS~3\2022\PROFES~1\VC\Tools\MSVC\1442~1.344\bin\Hostx64\x64\link.exe /nologo tools\clang\tools\extra\test\CMakeFiles\CTTestTidyModule.dir\clang-tidy\CTTestTidyModule.cpp.obj  /out:bin\CTTestTidyModule.dll /implib:lib\CTTestTidyModule.lib /pdb:bin\CTTestTidyModule.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO  lib\clang-tidy.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "C:\PROGRA~1\MICROS~3\2022\PROFES~1\VC\Tools\MSVC\1442~1.344\bin\Hostx64\x64\link.exe /nologo tools\clang\tools\extra\test\CMakeFiles\CTTestTidyModule.dir\clang-tidy\CTTestTidyModule.cpp.obj /out:bin\CTTestTidyModule.dll /implib:lib\CTTestTidyModule.lib /pdb:bin\CTTestTidyModule.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO lib\clang-tidy.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST:EMBED,ID=2" failed (exit code 1120) with the following output:

CTTestTidyModule.cpp.obj : error LNK2001: unresolved external symbol "class clang::ast_matchers::internal::VariadicDynCastAllOfMatcher<class clang::Decl,class clang::TranslationUnitDecl> const clang::ast_matchers::translationUnitDecl" (?translationUnitDecl@ast_matchers@clang@@3V?$VariadicDynCastAllOfMatcher@VDecl@clang@@VTranslationUnitDecl@2@@internal@12@B)
bin\CTTestTidyModule.dll : fatal error LNK1120: 1 unresolved externals

Can somebody please help me.

@john-brawn-arm maybe

John is on holiday at the moment, and I can’t help with the linker error, but I can fix those python warnings: [Python] Use raw string literals for regexes by ostannard · Pull Request #120401 · llvm/llvm-project · GitHub

@ostannard Thanks for the quick fix of the SyntaxWarnings.

Regarding the linker error - I tried to build the main branch also and got the exact same linker error.