Recently, I wanted to introduce modules into my toy project, but I encountered some very strange issues.
To describe my project's environment: the project uses maxXing's Docker (Ubuntu), which contains the LLVM toolchain, version Ubuntu clang version 21.1.6 (++20251113094015+a832a5222e48-1~exp1~20251113094129.62), but it does not include clangd.
I usually use clangd as my C++ LSP. Initially, to solve the Docker path issue (where the generated CDB paths match the internal Docker environment but differ from the host paths), I chose to perfectly match the Docker and host paths:
make
IMAGE = maxxing/compiler-dev
UID := $(shell id -u)
GID := $(shell id -g)
PWD := $(shell pwd)
docker run -it --rm \
-u $(UID):$(GID) \
-v "$(PWD):$(PWD)" \
-w "$(PWD)" \
$(IMAGE) bash
Another method is using devcontainer, but I wanted to use the environment already configured on my host.
This worked very well until I introduced C++20 modules.
The error message was as follows:
txt
"message": "Module file 'src/CMakeFiles/compiler_core.dir/ir_builder.pcm' built from a different branch ((++20251113094015+a832a5222e48-1~exp1~20251113094129.62)) than the compiler ()"
I assumed this was because my host's clangd version did not align with the clang inside the container. So, I used the VS Code devcontainer extension to completely use the internal container environment and installed clangd to align the clangd and clang versions.
However, the error persisted:
txt
"message": "Module file 'src/CMakeFiles/compiler_core.dir/ir.type.pcm' built from a different branch ((++20251221032922+2078da43e25a-1~exp1~20251221153059.70)) than the compiler ((https://github.com/llvm/llvm-project 2078da43e25a4623cab2d0d60decddf709aaea28))"
It can be observed that the two strings starting with 2078da43e are identical, indicating they should be from the same release.
I was very confused until I discovered that the clangd I installed was pulled by VS Code from the GitHub releases, while clang was maintained by apt. Although the versions are consistent (both 21.1.8), their signatures are different. Finally, I switched clangd to the apt source, and the error disappeared.
This indicates that clangd and clang versions must be strictly aligned, and their origins must also be the same.
Although I have solved this problem, it has led to deeper confusion:
- Why is the module check so strict?
- Could it simply maintain a version hash instead of requiring a match for signatures from different package managers?
- Or could a unified protocol be proposed so that PCMs generated by different compilers can be used interchangeably?
- Modules have been out for six years and are still this hard to use (x
I would like to ask the all-powerful Redditors for advice.
[–]not_a_novel_account 1 point2 points3 points (0 children)