Building Clazy

Following https://github.com/KDE/clazy?tab=readme-ov-file#windows

I checked out llvm-19.1.7. build llvm takes 4 hours…

install llvm

installed llvm via

cmake --install .

and add bin-path to Path via the shortcut

rundll32 sysdm.cpl,EditEnvironmentVariables

build clazy

cmake -DCMAKE_INSTALL_PREFIX=C:\src\clazy_install -DLLVM_ROOT=C:C:\src\llvm-project-install\ -DCMAKE_BUILD_TYPE=Release -G "Ninja" -B build

However I get weird error:

C:\src\clazy [(1.13)]> cmake --build build
[1/2] Linking CXX shared library bin\ClazyPlugin.dll
FAILED: bin/ClazyPlugin.dll lib/libClazyPlugin.dll.a
C:\WINDOWS\system32\cmd.exe /C "cd . && C:\Users\fts-guest-05600\scoop\apps\gcc\current\bin\g++.exe -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -fno-exceptions -fno-rtti -O3 -DNDEBUG   -shared -o bin\ClazyPlugin.dll -Wl,--out-implib,lib\libClazyPlugin.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\ClazyPlugin.rsp && cd ."
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangParse.a(ParseObjc.cpp.obj):ParseObjc.cpp:(.text$_ZN5clang6Parser31ParseObjCAtInterfaceDeclarationENS_14SourceLocationERNS_16ParsedAttributesE+0x5e6): undefined reference to `clang::ODRDiagsEmitter::diagnoseMismatch(clang::ObjCInterfaceDecl const*, clang::ObjCInterfaceDecl const*, clang::ObjCInterfaceDecl::DefinitionData const*) const'
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangParse.a(ParseObjc.cpp.obj):ParseObjc.cpp:(.text$_ZN5clang6Parser30ParseObjCAtProtocolDeclarationENS_14SourceLocationERNS_16ParsedAttributesE+0x38e): undefined reference to `clang::ODRDiagsEmitter::diagnoseMismatch(clang::ObjCProtocolDecl const*, clang::ObjCProtocolDecl const*, clang::ObjCProtocolDecl::DefinitionData const*) const'
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangSerialization.a(ASTReader.cpp.obj):ASTReader.cpp:(.text$_ZN5clang9ASTReader21diagnoseOdrViolationsEv+0x102c): undefined reference to `clang::ODRDiagsEmitter::getOwningModuleNameForDiagnostic[abi:cxx11](clang::Decl const*)'
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangSerialization.a(ASTReader.cpp.obj):ASTReader.cpp:(.text$_ZN5clang9ASTReader21diagnoseOdrViolationsEv+0x107e): undefined reference to `clang::ODRDiagsEmitter::getOwningModuleNameForDiagnostic[abi:cxx11](clang::Decl const*)'
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangSerialization.a(ASTReader.cpp.obj):ASTReader.cpp:(.text$_ZN5clang9ASTReader21diagnoseOdrViolationsEv+0x14d4): undefined reference to `clang::ODRDiagsEmitter::diagnoseMismatch(clang::FunctionDecl const*, clang::FunctionDecl const*) const'
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangSerialization.a(ASTReader.cpp.obj):ASTReader.cpp:(.text$_ZN5clang9ASTReader21diagnoseOdrViolationsEv+0x1a43): undefined reference to `clang::ODRDiagsEmitter::diagnoseMismatch(clang::ObjCProtocolDecl const*, clang::ObjCProtocolDecl const*, clang::ObjCProtocolDecl::DefinitionData const*) const'
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangSerialization.a(ASTReader.cpp.obj):ASTReader.cpp:(.text$_ZN5clang9ASTReader21diagnoseOdrViolationsEv+0x1ad3): undefined reference to `clang::ODRDiagsEmitter::diagnoseMismatch(clang::ObjCInterfaceDecl const*, clang::ObjCInterfaceDecl const*, clang::ObjCInterfaceDecl::DefinitionData const*) const'
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangSerialization.a(ASTReader.cpp.obj):ASTReader.cpp:(.text$_ZN5clang9ASTReader21diagnoseOdrViolationsEv+0x1b57): undefined reference to `clang::ODRDiagsEmitter::diagnoseMismatch(clang::EnumDecl const*, clang::EnumDecl const*) const'
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangSerialization.a(ASTReader.cpp.obj):ASTReader.cpp:(.text$_ZN5clang9ASTReader21diagnoseOdrViolationsEv+0x1be7): undefined reference to `clang::ODRDiagsEmitter::diagnoseMismatch(clang::RecordDecl const*, clang::RecordDecl const*) const'
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangSerialization.a(ASTReader.cpp.obj):ASTReader.cpp:(.text$_ZN5clang9ASTReader21diagnoseOdrViolationsEv+0x1c27): undefined reference to `clang::ODRDiagsEmitter::diagnoseMismatch(clang::CXXRecordDecl const*, clang::CXXRecordDecl const*, clang::CXXRecordDecl::DefinitionData const*) const'
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangToolingCore.a(Replacement.cpp.obj):Replacement.cpp:(.text$_ZNSt8_Rb_treeIN5clang6FileIDESt4pairIKS1_NS0_13RewriteBufferEESt10_Select1stIS5_ESt4lessIS1_ESaIS5_EE8_M_eraseEPSt13_Rb_tree_nodeIS5_E.isra.0+0x31): undefined reference to `clang::RopePieceBTree::~RopePieceBTree()'
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangToolingCore.a(Replacement.cpp.obj):Replacement.cpp:(.text$_ZNSt8_Rb_treeIN5clang6FileIDESt4pairIKS1_NS0_13RewriteBufferEESt10_Select1stIS5_ESt4lessIS1_ESaIS5_EE8_M_eraseEPSt13_Rb_tree_nodeIS5_E.isra.0+0x3a): undefined reference to `clang::DeltaTree::~DeltaTree()'
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangToolingCore.a(Replacement.cpp.obj):Replacement.cpp:(.text$_ZNK5clang7tooling11Replacement5applyERNS_8RewriterE+0xa3): undefined reference to `clang::Rewriter::ReplaceText(clang::SourceLocation, unsigned int, llvm::StringRef)'
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangToolingCore.a(Replacement.cpp.obj):Replacement.cpp:(.text$_ZN5clang7tooling20applyAllReplacementsB5cxx11EN4llvm9StringRefERKNS0_12ReplacementsE+0xd37): undefined reference to `clang::Rewriter::getEditBuffer(clang::FileID)'
C:/Users/fts-guest-05600/scoop/apps/gcc/13.2.0/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/src/llvm-project-install/lib/libclangToolingCore.a(Replacement.cpp.obj):Replacement.cpp:(.text$_ZN5clang7tooling20applyAllReplacementsB5cxx11EN4llvm9StringRefERKNS0_12ReplacementsE+0xd42): undefined reference to `clang::RewriteBuffer::write(llvm::raw_ostream&) const'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

I retried but the same error.

Then I tried it using msys2 but get the error “llvm-config” not found. weired..

rebuild llvm was certainly not an option.

There are several files: Replacement.cpp, ASTReader.cpp, and ParseObjc.cpp.

I find them using fzf and edited them:

Then I build llvm incrementally and installed it, then run ninja again in clazy build directory, but it’s the same error…

rebuild clazy

I think there might be a mix for scoop llvm and custom built llvm. so I uninstalled llvm again (it was used in llvm build and get re-installed..), then I deleted the build directory, and re-run the cmake command:

cmake -DCMAKE_INSTALL_PREFIX=C:\src\clazy_install -DCLANG_LIBRARY_IMPORT=C:\src\llvm-project-install\lib\libclang.dll.a -DCMAKE_BUILD_TYPE=Release -G "Ninja" -B build -DLLVM_ROOT=C:\src\llvm-project-install\

however the error was still the same…

rebuild clazy again

This time I switched to master branch. it’s still the same error. I give up.

rebuild llvm

So.. I get here.

rerun:

cmake -DCMAKE_INSTALL_PREFIX=C:\src\llvm-project-install -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -G "Ninja" ..\llvm-project\llvm\ -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc -DCMAKE_ASM_COMPILER=gcc -DCMAKE_BUILD_TYPE="Release"

then:

ninja -j1 -k0

however it still failed.