This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Blog

This is the blog section. It has two categories: News and Releases.

Files in these directories will be listed in reverse chronological order.

Cpp

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

  1. add colors
  2. 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

Go

Fix Hugo URL open problem

I use hugo for my staic website.

however, while writing docs, a queer problem happened: the url print in console is always broken.

Web Server is available at //localhost:1313/ (bind address 127.0.0.1)

I download the source code and start debugging. I use an example site freshed generated by hugo compared to my own site.

turned out that I didn’t set the baseURL in my configuration.

However, after set it, another problem happened:

  1. I use firebase hosting
  2. it can provide convenient function to see site go live even in the PR stage
  3. the URL prefix changed
  4. all the following links points to old URL!

So I have to fix it by creating a fork.

The result is as follows:

https://github.com/soda92/hugo/pull/1/files

url := serverURL
if !strings.HasPrefix(url, "http") {
    url = "http:" + url
}
c.r.Printf("Web Server is available at %s (bind address %s) %s\n", url, c.serverInterface, roots[i])

build

build part is easy. just run:

go build -tags extended .

then copy hugo.exe to a bin dir in $Env:PATH.

Zig

Zig's Build System is fundamentally Broken

  • does not support proxy
  • confusing hashes
  • build script incompatible between zig versions

It takes me several hours for fixing build script for ffmpeg, because it’s not an easy task.

download dependencies and put them in right place

https://github.com/soda92/ffmpeg/blob/download/update_zon.py

https://github.com/soda92/ffmpeg/blob/download/update_zon2.py

update .zig.zon files to point to these locations

https://github.com/soda92/ffmpeg/blob/download/update_zon3.py

And it also support github repos…

And the unpack need to match the name

https://github.com/soda92/ffmpeg/blob/download/update_zon4.py

https://github.com/soda92/ffmpeg/blob/download/update_zon5.py

And everything is breaking

https://github.com/soda92/ffmpeg/blob/download/update_zon6.py

fix taken from https://github.com/natecraddock/ziglua/pull/131

Well it only support path relative to build root

https://github.com/soda92/ffmpeg/blob/download/update_zon7.py

It’s so many patches that I need a runnner

import subprocess
from pathlib import Path
import send2trash

if Path("tmp").exists():
    # send2trash.send2trash("tmp")
    pass
if Path("unzip").exists():
    send2trash.send2trash("unzip")
subprocess.run(["git", "restore", "build.zig.zon"])
subprocess.run(["python", "update_zon.py"])
subprocess.run(["python", "update_zon2.py"])
subprocess.run(["python", "update_zon3.py"])
subprocess.run(["python", "update_zon2.py"])
subprocess.run(["python", "update_zon4.py"])
subprocess.run(["python", "update_zon5.py"])
subprocess.run(["python", "update_zon6.py"])
subprocess.run(["python", "update_zon7.py"])
zig build
install
└─ install show_metadata_c
   └─ zig build-exe show_metadata_c Debug native
      └─ zig build-lib ffmpeg Debug native
         └─ run nasm (resample.o)
            └─ zig build-exe nasm ReleaseFast native 79 errors
C:\src\ffmpeg\unzip\github.com\allyourcodebase\nasm\archive\refs\tags\nasm-2.16.1-3\include/compiler.h:101:11: error: 'endian.h' file not found
# include <endian.h>
          ^~~~~~~~~~~
C:\src\ffmpeg\unzip\github.com\allyourcodebase\nasm\archive\refs\tags\nasm-2.16.1-3\nasmlib/alloc.c:38:10: note: in file included from C:\src\ffmpeg\unzip\github.com\allyourcodebase\nasm\archive\refs\tags\nasm-2.16.1-3\nasmlib/alloc.c:38:
#include "compiler.h"
         ^

Later, I tried to undef these macros so the <endian.h> won’t be included:

111 222

But due to comples caching it only works at the first time (change .h before run zig). I have runner script so it’s not a problem.

Then I deleted nasm:

diff --git a/build.zig b/build.zig
index a2cbbeaef0..6d57e9d304 100644
--- a/build.zig
+++ b/build.zig
@@ -843,10 +843,7 @@ pub fn build(b: *std.Build) void {
     };

     @setEvalBranchQuota(2500);
-    const config_asm = b.addConfigHeader(.{
-        .style = .nasm,
-        .include_path = "config.asm",
-    }, common_config);
+

     const config_h = b.addConfigHeader(.{
         .style = .blank,
@@ -3129,40 +3126,7 @@ pub fn build(b: *std.Build) void {
     });
     switch (t.cpu.arch) {
         .x86_64, .x86 => {
-            // For x86 there is one additional complication which is compiling .asm
-            // files into object files with NASM.
-            const nasm_dep = b.dependency("nasm", .{
-                .optimize = .ReleaseFast,
-            });
-            const nasm_exe = nasm_dep.artifact("nasm");
-
-            for (all_sources) |input_file| {
-                if (!std.mem.endsWith(u8, input_file, ".asm")) continue;
-
-                const output_basename = basenameNewExtension(b, input_file, ".o");
-                const nasm_run = b.addRunArtifact(nasm_exe);
-
-                // nasm requires a trailing slash on include directories
-                const include_dir = b.fmt("-I{s}/", .{std.fs.path.dirname(input_file).?});       
-
-                nasm_run.addArgs(&.{
-                    "-f",
-                    "elf64",
-                    "-g",
-                    "-F",
-                    "dwarf",
-                    "-I./",
-                    include_dir,
-                });
-
-                nasm_run.addArgs(&.{"--include"});
-                nasm_run.addFileArg(config_asm.getOutput());
-
-                nasm_run.addArgs(&.{"-o"});
-                lib.addObjectFile(nasm_run.addOutputFileArg(output_basename));
-
-                nasm_run.addFileArg(b.path(input_file));
-            }
+
         },
         else => {},
     }
diff --git a/run.py b/run.py
index 79c8f5e494..8d4ecb157c 100644
--- a/run.py
+++ b/run.py
@@ -16,3 +16,4 @@ subprocess.run(["python", "update_zon4.py"])
 subprocess.run(["python", "update_zon5.py"])
 subprocess.run(["python", "update_zon6.py"])
 subprocess.run(["python", "update_zon7.py"])
+subprocess.run(["python", "update_zon8.py"])
diff --git a/update_zon8.py b/update_zon8.py
new file mode 100644
index 0000000000..9282d781a0
--- /dev/null
+++ b/update_zon8.py
@@ -0,0 +1,4 @@
+import shutil
+
+shutil.copy(r"z_patched_files\compiler.h", r"unzip\github.com\allyourcodebase\nasm\archive\refs\tags\nasm-2.16.1-3\include\compiler.h")
+shutil.copy(r"z_patched_files\file.h", r"unzip\github.com\allyourcodebase\nasm\archive\refs\tags\nasm-2.16.1-3\nasmlib\file.h")
\ No newline at end of file

In the end, I only find it does not support Windows:

zig build
install
└─ install show_metadata_c
   └─ zig build-exe show_metadata_c Debug native
      └─ zig build-lib ffmpeg Debug native 449 errors
C:\\src\\ffmpeg/libavutil/thread.h:28:10: error: 'sys/prctl.h' file not found
#include <sys/prctl.h>
         ^~~~~~~~~~~~~~
C:\\src\\ffmpeg\\libavcodec/aactab.c:36:10: note: in file included from C:\\src\\ffmpeg\\libavcodec/aactab.c:36:
#include "libavutil/thread.h"
         ^
C:\\src\\ffmpeg\\libswscale/utils.c:25:9: error: '_DARWIN_C_SOURCE' macro redefined
#define _DARWIN_C_SOURCE // needed for MAP_ANON
        ^
<command line>:9:9: note: previous definition is here
C:\\src\\ffmpeg\\libswscale/utils.c:31:10: error: 'sys/mman.h' file not found
#include <sys/mman.h>
         ^~~~~~~~~~~~~
C:\\src\\ffmpeg/libavutil/thread.h:28:10: error: 'sys/prctl.h' file not found
#include <sys/prctl.h>
         ^~~~~~~~~~~~~~
C:\\src\\ffmpeg\\libavcodec/aacdec.c:260:10: note: in file included from C:\\src\\ffmpeg\\libavcodec/aacdec.c:260:
#include "aacdec_template.c"
         ^
C:\\src\\ffmpeg\\libavcodec/aacdec_template.c:93:10: note: in file included from C:\\src\\ffmpeg\\libavcodec/aacdec_template.c:93:
#include "libavutil/thread.h"
         ^
C:\\src\\ffmpeg/libavutil/thread.h:28:10: error: 'sys/prctl.h' file not found
#include <sys/prctl.h>
         ^~~~~~~~~~~~~~
C:\\src\\ffmpeg\\libavcodec/4xm.c:34:10: note: in file included from C:\\src\\ffmpeg\\libavcodec/4xm.c:34:
#include "libavutil/thread.h"
         ^
C:\\src\\ffmpeg/libavutil/thread.h:28:10: error: 'sys/prctl.h' file not found
#include <sys/prctl.h>
         ^~~~~~~~~~~~~~

wsl

In WSL, I can successfully build it, but other libraries are still missing: skip

 zig cc remux.c -I ../../zig-out/include/ -L../../zig-out/lib -lffmpeg
ld.lld: error: undefined symbol: deflate
>>> referenced by pngenc.c:575 (libavcodec/pngenc.c:575)
>>>               /home/soda/src/ffmpeg/.zig-cache/o/f6bd17677bf017a3f11ac8deec19ad74/pngenc.o:(encode_frame) in archive ../../zig-out/lib/libffmpeg.a
>>> referenced by pngenc.c:360 (libavcodec/pngenc.c:360)
>>>               /home/soda/src/ffmpeg/.zig-cache/o/f6bd17677bf017a3f11ac8deec19ad74/pngenc.o:(png_write_iccp) in archive ../../zig-out/lib/libffmpeg.a
>>> referenced by pngenc.c:285 (libavcodec/pngenc.c:285)
>>>               /home/soda/src/ffmpeg/.zig-cache/o/f6bd17677bf017a3f11ac8deec19ad74/pngenc.o:(png_write_row) in archive ../../zig-out/lib/libffmpeg.a
>>> referenced 6 more times

ld.lld: error: undefined symbol: vorbis_analysis
>>> referenced by libvorbisenc.c:323 (libavcodec/libvorbisenc.c:323)
>>>               /home/soda/src/ffmpeg/.zig-cache/o/37be7e7fd754c225437fd77c2973878b/libvorbisenc.o:(libvorbis_encode_frame) in archive ../../zig-out/lib/libffmpeg.a

ld.lld: error: undefined symbol: vorbis_bitrate_addblock
>>> referenced by libvorbisenc.c:325 (libavcodec/libvorbisenc.c:325)
>>>               /home/soda/src/ffmpeg/.zig-cache/o/37be7e7fd754c225437fd77c2973878b/libvorbisenc.o:(libvorbis_encode_frame) in archive ../../zig-out/lib/libffmpeg.a

ld.lld: error: undefined symbol: vorbis_bitrate_flushpacket
>>> referenced by libvorbisenc.c:329 (libavcodec/libvorbisenc.c:329)
>>>               /home/soda/src/ffmpeg/.zig-cache/o/37be7e7fd754c225437fd77c2973878b/libvorbisenc.o:(libvorbis_encode_frame) in archive ../../zig-out/lib/libffmpeg.a

ld.lld: error: undefined symbol: lame_init
>>> referenced by libmp3lame.c:102 (libavcodec/libmp3lame.c:102)
>>>               /home/soda/src/ffmpeg/.zig-cache/o/f782ff6a63f6fbc56cfd619f4a10734b/libmp3lame.o:(mp3lame_encode_init) in archive ../../zig-out/lib/libffmpeg.a

ld.lld: error: undefined symbol: lame_set_num_channels
>>> referenced by libmp3lame.c:106 (libavcodec/libmp3lame.c:106)
>>>               /home/soda/src/ffmpeg/.zig-cache/o/f782ff6a63f6fbc56cfd619f4a10734b/libmp3lame.o:(mp3lame_encode_init) in archive ../../zig-out/lib/libffmpeg.a

ld.lld: error: undefined symbol: uncompress
>>> referenced by cscd.c:98 (libavcodec/cscd.c:98)
>>>               /home/soda/src/ffmpeg/.zig-cache/o/b092a0b94e6b0ffb723a0d53d3e07bc0/cscd.o:(decode_frame) in archive ../../zig-out/lib/libffmpeg.a
>>> referenced by dxa.c:252 (libavcodec/dxa.c:252)
>>>               /home/soda/src/ffmpeg/.zig-cache/o/d207d5b24fcf278c29bf3d5cab83d101/dxa.o:(decode_frame) in archive ../../zig-out/lib/libffmpeg.a
>>> referenced by exr.c:204 (libavcodec/exr.c:204)
>>>               /home/soda/src/ffmpeg/.zig-cache/o/20f6eb5f10888146f12c2115f7326223/exr.o:(zip_uncompress) in archive ../../zig-out/lib/libffmpeg.a
>>> referenced 13 more times

ld.lld: error: undefined symbol: inflateInit2_
>>> referenced by http.c:852 (libavformat/http.c:852)
>>>               /home/soda/src/ffmpeg/.zig-cache/o/4a5715c1a50261c769a4e1f62f7bfa14/http.o:(parse_content_encoding) in archive ../../zig-out/lib/libffmpeg.a

ld.lld: error: undefined symbol: zlibCompileFlags
>>> referenced by http.c:857 (libavformat/http.c:857)
>>>               /home/soda/src/ffmpeg/.zig-cache/o/4a5715c1a50261c769a4e1f62f7bfa14/http.o:(parse_content_encoding) in archive ../../zig-out/lib/libffmpeg.a

msys2

In fact, build ffmpeg is already a non-trival task on Windows. MSYS2 has 83 packages for dealing with it:

pacman -S ucrt64/mingw-w64-ucrt-x86_64-ffmpeg
resolving dependencies...
looking for conflicting packages...
warning: dependency cycle detected:
warning: mingw-w64-ucrt-x86_64-harfbuzz will be installed before its mingw-w64-ucrt-x86_64-freetype dependency
warning: dependency cycle detected:
warning: mingw-w64-ucrt-x86_64-libwebp will be installed before its mingw-w64-ucrt-x86_64-libtiff dependency

Packages (83) mingw-w64-ucrt-x86_64-aom-3.11.0-1  mingw-w64-ucrt-x86_64-brotli-1.1.0-4  mingw-w64-ucrt-x86_64-cairo-1.18.2-2
              mingw-w64-ucrt-x86_64-dav1d-1.5.0-1  mingw-w64-ucrt-x86_64-fontconfig-2.15.0-2
              mingw-w64-ucrt-x86_64-freetype-2.13.3-1  mingw-w64-ucrt-x86_64-frei0r-plugins-2.3.3-2
              mingw-w64-ucrt-x86_64-fribidi-1.0.16-1  mingw-w64-ucrt-x86_64-gdk-pixbuf2-2.42.12-4
              mingw-w64-ucrt-x86_64-giflib-5.2.2-1  mingw-w64-ucrt-x86_64-glib2-2.82.4-1
              mingw-w64-ucrt-x86_64-glslang-15.1.0-1  mingw-w64-ucrt-x86_64-gnutls-3.8.8-1
              mingw-w64-ucrt-x86_64-graphite2-1.3.14-3  mingw-w64-ucrt-x86_64-gsm-1.0.22-1
              mingw-w64-ucrt-x86_64-harfbuzz-10.2.0-1  mingw-w64-ucrt-x86_64-highway-1.2.0-1
              mingw-w64-ucrt-x86_64-imath-3.1.12-2  mingw-w64-ucrt-x86_64-jbigkit-2.1-5  mingw-w64-ucrt-x86_64-lame-3.100-3
              mingw-w64-ucrt-x86_64-lcms2-2.16-1  mingw-w64-ucrt-x86_64-lerc-4.0.0-1  mingw-w64-ucrt-x86_64-libass-0.17.3-1
              mingw-w64-ucrt-x86_64-libbluray-1.3.4-1  mingw-w64-ucrt-x86_64-libcaca-0.99.beta20-6
              mingw-w64-ucrt-x86_64-libdatrie-0.2.13-3  mingw-w64-ucrt-x86_64-libdeflate-1.23-1
              mingw-w64-ucrt-x86_64-libdovi-3.3.1-1  mingw-w64-ucrt-x86_64-libexif-0.6.24-3
              mingw-w64-ucrt-x86_64-libgme-0.6.3-3  mingw-w64-ucrt-x86_64-libidn2-2.3.7-2
              mingw-w64-ucrt-x86_64-libjpeg-turbo-3.1.0-1  mingw-w64-ucrt-x86_64-libjxl-0.11.1-1
              mingw-w64-ucrt-x86_64-liblc3-1.1.1-2  mingw-w64-ucrt-x86_64-libmodplug-0.8.9.0-4
              mingw-w64-ucrt-x86_64-libmysofa-1.3.1-1  mingw-w64-ucrt-x86_64-libogg-1.3.5-1
              mingw-w64-ucrt-x86_64-libplacebo-7.349.0-1  mingw-w64-ucrt-x86_64-libpng-1.6.45-1
              mingw-w64-ucrt-x86_64-librsvg-2.59.2-1  mingw-w64-ucrt-x86_64-libsoxr-0.1.3-5
              mingw-w64-ucrt-x86_64-libssh-0.11.1-2  mingw-w64-ucrt-x86_64-libtasn1-4.19.0-1
              mingw-w64-ucrt-x86_64-libthai-0.1.29-3  mingw-w64-ucrt-x86_64-libtheora-1.1.1-7
              mingw-w64-ucrt-x86_64-libtiff-4.7.0-1  mingw-w64-ucrt-x86_64-libunibreak-6.1-1
              mingw-w64-ucrt-x86_64-libunistring-1.3-1  mingw-w64-ucrt-x86_64-libva-2.22.0-2
              mingw-w64-ucrt-x86_64-libvorbis-1.3.7-2  mingw-w64-ucrt-x86_64-libvpl-2.14.0-1
              mingw-w64-ucrt-x86_64-libvpx-1.15.0-1  mingw-w64-ucrt-x86_64-libwebp-1.5.0-1
              mingw-w64-ucrt-x86_64-libx264-0.164.r3161.a354f11-3  mingw-w64-ucrt-x86_64-libxml2-2.12.9-2
              mingw-w64-ucrt-x86_64-lzo2-2.10-2  mingw-w64-ucrt-x86_64-nettle-3.10.1-1  mingw-w64-ucrt-x86_64-openal-1.24.2-1
              mingw-w64-ucrt-x86_64-opencore-amr-0.1.6-1  mingw-w64-ucrt-x86_64-openexr-3.3.2-1
              mingw-w64-ucrt-x86_64-openjpeg2-2.5.3-1  mingw-w64-ucrt-x86_64-opus-1.5.2-1
              mingw-w64-ucrt-x86_64-p11-kit-0.25.5-1  mingw-w64-ucrt-x86_64-pango-1.56.0-1  mingw-w64-ucrt-x86_64-pcre2-10.44-2
              mingw-w64-ucrt-x86_64-pixman-0.44.2-1  mingw-w64-ucrt-x86_64-python-packaging-24.2-1
              mingw-w64-ucrt-x86_64-rav1e-0.7.1-4  mingw-w64-ucrt-x86_64-rtmpdump-2.4.r99.f1b83c1-1
              mingw-w64-ucrt-x86_64-shaderc-2024.4-1  mingw-w64-ucrt-x86_64-speex-1.2.1-1
              mingw-w64-ucrt-x86_64-speexdsp-1.2.1-1  mingw-w64-ucrt-x86_64-spirv-cross-1~1.4.304.0-2
              mingw-w64-ucrt-x86_64-spirv-tools-3~1.4.304.0-1  mingw-w64-ucrt-x86_64-srt-1.5.4-1
              mingw-w64-ucrt-x86_64-svt-av1-2.3.0-2  mingw-w64-ucrt-x86_64-vid.stab-1.1.1-1
              mingw-w64-ucrt-x86_64-wineditline-2.208-1  mingw-w64-ucrt-x86_64-x265-4.1-2
              mingw-w64-ucrt-x86_64-xvidcore-1.3.7-4  mingw-w64-ucrt-x86_64-zimg-3.0.5-2
              mingw-w64-ucrt-x86_64-zvbi-0.2.42.r41.gb4cef50-1  mingw-w64-ucrt-x86_64-ffmpeg-7.1-4

Total Installed Size:  800.02 MiB

MSYS2 Program Collection

Intro

MSYS2 was a great development environment.

GDB is working in MSYS2, with libstdc++ visualizer and python support; qt libraries are easy to install, and qt-creator is readily available; it has precompiled ffmpeg, which was very complex to build manually; and even has complete 32-bit support.

(to search for a package’s variants you can use the package search web page)

I have created several tools to use it.

windeployqt

In my early days I do Qt development. However qt on Windows is only provided by the Qt online installer, which I didn’t like.

Also, deploying Qt was very complex. MSYS2 make these two things simple.

This project can deploy a Qt program for Windows to use.

msys2-env

Although Python can use Qt as GUI via PySide, many people find GTK more lightweight, and it is widely used and supported in Linux.

However, GTK don’t have precompiled libraries on Windows, which makes it hard for Windows users to use. for example, bleachbit use a complex custom compile process to make its Windows release.

MSYS2 has packaged these libraries, but python environment is usually perceived as a ‘.venv’ folder, rather than a global installation.

This project create a MSYS2 environment and Python interpreter in a venv-like structure, and provide several helpful tools for interacting with MSYS2.

msys2-wrapper

Speaking using MSYS2, a common way was to use its built-in msys2_shell.cmd . however, this method creates an annoying prompt when pressed CTRL+C.

A natural solution was to convert Batch script to powershell, but I don’t know PowerShell much, and there are no existing tools to help the translation.

So I created this project for launch the msys2 shell without the problem of bat .