This is the multi-page printable view of this section. Click here to print.
Cpp
- fixing lsp for Windows
- Packaging MSYS2 as virtual environment
- Building Clazy
- Add Icon to Qt Exe
- Fixing Qt Deploy
fixing lsp for Windows
For a long time, clangd on Windows is not quite usable without Visual Studio. It’s time for a fix!
cannot find <iostream>
First we need to fix the compile_commands.json
. from the experience of project soda_clang, I quickly added the GCC include directories to the compilation database.
too many errors, stopping now
The MinGW header files contains many symbol Clangd didn’t recognize; I created a virtual directory, removing the symbols, and copying things over.
The compile db need also be changed to point to the new virtual directory.
There is always formatting problem
Boringly looking up clang-format doc, and find a somewhat consistant style. then use a script to format all files automatically on every build.
(There is also another app, Clang Format Editor, stated that it can detect style from code. but it’s not usable. the styles are all error!)
Cmake arguments are cubersome and hard to remember
I switched to cmake presets. (also use a script to generate the user presets.)
Also I created simple Makefile
s to simple build. (thanks to makefiletutorial)
Need debugging
The gdb shipped with scoop does not support python scripts, so stdc++ classes (string, vector…) cannot be displayed… I switched to TDM-GCC.
Also there is CodeLLDB extension for help (LLVM’s lldb-dap was not usable.)
So.. I built clang-format, clang, but not lldb. so I ended up installing llvm
from scoop again.
Also after uninstall gcc from PATH go compiler will throw an error. You need to pass the CC and CXX locations to go.
(also TDM-GCC’s include paths are different from scoop gcc. need to change the compile db again.)
Also TDM-GCC is using static libstdc++ so the -lstdc++ flag in cgo was not needed; and include it will cause error.
the end?
I was considering create a standalone tool (using Go) but don’t know where to start, and my knowledge about Golang isn’t enough.
After all that there are still minor issues (in the libstdc++ headers) but I decide to ignore them.
Packaging MSYS2 as virtual environment
bleachbit supports Windows, but the app looks somewhat ugly: no hidpi.
Also, the Windows 10 style is even worse. I don’t even want to take a screenshot.
I think gtk is also using custom rendering, similar to Qt. because I tried Mica for Windows and it shows a border area.
(Speaking of custom rendering, almost all modern GUI framework is using it: WinUI/WPF, Flutter, Qt/Qml, etc)
I cloned the repo and want to run it from source. However I soon have a problem: gi
(python-gobject) is not installed.
Turns out it need to be compiled and installed separately. The bleachbit project use a full custom build of both gtk and python so it’s not a problem.
Speaking of linux-like packages, I soon turns to MSYS2. install it was easy: there is already python-gobject binding and even pywin32; both as pacman packages.
However I wound like a venv
-like setup - a separate MSYS2 env for each project.
Enter msys2_env
: https://pypi.org/project/msys2-env/.
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.
Add Icon to Qt Exe
Find Icon
https://fonts.google.com/icons
edit it
- add colors
- convert to ico
add to project
cmake:
set(app_icon_resource_windows "${CMAKE_CURRENT_SOURCE_DIR}/app.rc")
qt_add_executable(appqtquick_untitled
main.cpp ${app_icon_resource_windows}
)
app.rc:
IDI_ICON1 ICON "program.ico"
program.ico
: converted icon copied and renamed
result
files
app
taskbar
reference
demo project: https://github.com/soda92/qtquick_untitled
qt docs: https://doc.qt.io/qt-6/appicon.html
Fixing Qt Deploy
the project: https://pypi.org/project/windeployqt/
install Qt
Install Qt Creator on Windows is complex even using MSYS2. and it didn’t create useful shortcuts.
I write a Python package for it: https://pypi.org/project/install-qt-creator/
deploy Qt
Also, to deploy Qt is also a pain. one need to deal with complex dependencies, also, QMLDIR was not automatically set, and QtQuick base files are hard to locate…
It seems on newer Qt, there is a cmake function to create and copy Main.qml to a qmldir automatically:
qt_add_qml_module(appqtquick_untitled
URI qtquick_untitled
VERSION 1.0
QML_FILES
Main.qml
)
it results in a directory inside build directory. the code to load it is as follows:
engine.loadFromModule("qtquick_untitled", "Main");
well I also modify the script to add a function to copy this directory to output directory.
symbol links
I recalled that Windows has symbol links recently. this can simplify the build process. but I tried it that it cannot locate dll correctly.
So I added another function to copy the dll in-place…
create shortcut
it’s just a bounous