emscripten-core / emscripten-core/emscripten
emcmake: SIDE_MODULE can't find another SIDE_MODULE when link
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
**Version of emscripten/emsdk:**
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.13 (https://github.com/emscripten-core/emscripten/commit/531257621816c200bc7c3be53129494afd029aec)
clang version 15.0.0 (https://github.com/llvm/llvm-project 5c6ed60c517c47b25b6b25d8ac3666d0e746b0c3)
**Failing Project:**
A [test emcmake project](https://github.com/Keillion/emsdk-cheatlist/tree/2022-06-30-success).
mainModule -> sideModule (it's a SIDE_MODULE) -> cModule (another SIDE_MODULE)
mainModule offers system libraries.
sideModule offers `Class SideModule` needed by cModule.
cModule offers exported js API.
**Details:**
I want to tell sideModule what symbols need keepalive. Follow [#16762](https://github.com/emscripten-core/emscripten/issues/16762#issuecomment-1105353456).
But failed.
```cmake
set_target_properties(sideModule PROPERTIES
COMPILE_FLAGS " -s SIDE_MODULE=2 -fPIC"
LINK_FLAGS " -s SIDE_MODULE=2 -fPIC cModule.wasm"
SUFFIX ".wasm"
)
```
It reports:
```
make: make
[ 33%] Built target cModule
[ 50%] Building CXX object CMakeFiles/sideModule.dir/sideModule.cpp.o
[ 66%] Linking CXX executable sideModule.wasm
[ 66%] Built target sideModule
[ 83%] Linking CXX executable mainModule.js
em++: error: sideModule.wasm: shared library dependency not found: `cModule.wasm`
make[2]: *** [CMakeFiles/mainModule.dir/build.make:85: mainModule.js] Error 1
make[1]: *** [CMakeFiles/Makefile2:135: CMakeFiles/mainModule.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
emmake: error: 'make' failed (returned 2)
```
I tried use absolute path to cModule.wasm. Still failed.
So I need `SIDE_MODULE=1` and `EXPORT_ALL=1`.
```cmake
set_target_properties(sideModule PROPERTIES
COMPILE_FLAGS " -s SIDE_MODULE=1 -fPIC"
LINK_FLAGS " -s SIDE_MODULE=1 -fPIC -s EXPORT_ALL=1"
SUFFIX ".wasm"
)
```
It makes the SIDE_MODULE big in real production project.
**Walkaround:**
When I manually run `em++` in root dierctory. (cModule.wasm already built out)
```sh
em++ sideModule.cpp -o build/sideModule.wasm -sSIDE_MODULE=2 -fPIC build/cModule.w
asm
```
It succeeds.
So I guess it's something wrong in emcmake.
Contributor guide
Assessment
This issue has not been assessed yet.