[qtdeclarative] Linking against Qt libraries built with wasm32-emscripten triplet fail.
- Dominant language
- CMake
- Stars
- 27.5k
- Forks
- 7.7k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 321
Description
[repo.zip](https://github.com/user-attachments/files/20746365/repo.zip)
**Describe the bug**
I am attempting to build a personal QtQuick/QML application using the `wasm32-emscripten` triplet. While I was able to successfully build my ports. I was not able to link against the ports due to an issue with how `libpng` and `qtbase` was compiled.
When qtbase is compiled with features `concurrent` and `thread` enabled, it requires all of its dependencies to also be compiled to support muli-threading `-matomics -mbulk-memory` flags I believe are necessary. When attempting to link against qt libraries I get a link error explaining that `png.c.o` (from libpng) does not support `--shared-memory` because of this.
Now, I build with a small subset of vcpkg ports and features:
```json
{
"name": "myproject",
"version-string": "2025.6.15",
"port-version": 1,
"description": "Happy Father's Day",
"dependencies": [
{
"name": "qtbase",
"default-features": false,
"host": true
},
{
"name": "qtbase",
"default-features": false,
"features": [
"png",
"opengl",
"gles2"
],
"platform": "emscripten"
},
"qtdeclarative"
]
}
```
`qtdeclarative` ends up pulling in `qtlanguageserver` as a dependency. This, in turn, pulls in `concurrent` and `thread` as dependencies. When `concurrent` and `thread` are pulled in, that's when Qt expects its dependencies to be compiled for multi-threading.
I was able to solve my issue locally with a port overwrite that removes `qtlanguageserver` as a dependency.
I'm not sure why `qtlanguageserver` is needed as a dependency of `qtdeclarative` (at least for wasm) but everything was still able to compile just fine.
It would be nice if `qtbase` could force the necessary `-matomics -mbulk-memory` linker flags on its dependencies if a user does choose to build wasm for multi-threading.
**Environment**
- OS: Mac OS 15.5
- Compiler: emscripten
**To Reproduce**
Steps to reproduce the behavior:
1. Ensure all necessary system dependencies and tools are installed:
2. Download and extract [repo.zip](https://github.com/user-attachments/files/20746365/repo.zip)
3. Clone vcpkg and emscripten
```bash
git clone https://github.com/microsoft/vcpkg.git
git clone https://github.com/emscripten-core/emsdk.git
```
4. Install and activate emscripten
```bash
./emsdk/emsdk install 3.1.65
./emsdk/emsdk activate 3.1.65
source ./emsdk/emsdk_env.sh
```
5. Initialize vcpkg
```bash
./vcpkg/boostrap_vcpkg.sh
```
6. Configure and build project
```bash
cmake --preset wasm-debug
cmake --build --preset wasm-debug
```
**Expected behavior**
I expect to link my application against qt libraries with no linker errors.
**Failure logs**
```bash
[build] em++: warning: -pthread + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271 [-Wpthreads-mem-growth]
[build] wasm-ld: error: --shared-memory is disallowed by png.c.o because it was not compiled with 'atomics' or 'bulk-memory' features.
[build] em++: error: '/Users/user/Developer/myproject/emsdk/upstream/bin/wasm-ld @/var/folders/09/h8hy7_qn35ldjjc6xp7jgq7h0000gn/T/emscripten_q2v2s8yj.rsp.utf-8' failed (returned 1)
[build] ninja: build stopped: subcommand failed.
[proc] The command: /opt/homebrew/bin/cmake --build /Users/user/Developer/myproject/build --target install -- exited with code: 1
[driver] Build completed: 00:00:06.746
[build] Build finished with exit code 1
```
**Additional context**
To reiterate:
`qtdeclarative` pulls in `qtlanguageserver` which enables `qtbase[threads]`. This causes a multi-threaded wasm build for Qt but libpng is not compiled with emscripten to support this.
I was able to by pass this by removing the `qtlanguageserver` dependency using a custom port. Ideally, there would be an (feature?) option to configure Qt with or without multi-thread wasm support.
Contributor guide
Research direction
Inspect the qtdeclarative dependency definition and the qtbase feature wiring, especially how qtlanguageserver brings in concurrent and thread for wasm builds. Reproduce with the provided repo.zip and the wasm-debug CMake presets, then verify that the resulting application links without the libpng shared-memory error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, wasm
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100