emscripten-core / emscripten-core/emscripten
CMake shared libraries error: `shared library dependency not found in library path`
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I am compiling a large CMake code base to Emscripten, where certain libraries must be compiled into dynamically linked libraries. Since Emscripten doesn't support `add_library(... SHARED ...)` by default, I am trying to use [this workaround](https://github.com/emscripten-core/emscripten/issues/15276#issuecomment-1039349267) (another approach would be to use `add_executable(...)` with `-sSIDE_MDOULE=1` - but that would require refactoring of a very large number of CMake files, which I want to avoid).
That approach **almost** works, except for this: I am building two shared libraries, `A` and `B`. `A` defines that `B` should be added as a linked library:
```cmake
# A/CMakeLists.txt
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
add_library(A SHARED ${sources})
set_target_properties(A PROPERTIES SUFFIX ".wasm")
target_link_options(A PRIVATE "-sSIDE_MODULE=1")
target_compile_options(A PRIVATE "-sSIDE_MODULE=1")
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
````
```cmake
# B/CMakeLists.txt
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
# ... same as A
target_link_libraries(B A) # Link library A into B
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
````
With that, the build fails with this error:
```
em++: error: /project/libB.wasm: shared library dependency not found in library path: `libA.wasm`. (library path: ['/project/runtime/output/wasm32-emscripten/build/vcpkg_installed/wasm32-emscripten/lib', '/project/runtime/output/wasm32-emscripten/build/vcpkg_installed/wasm32-emscripten/debug/lib', '/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic']
```
Is there a way to modify this library path, mentioned in the error message? Has anyone managed to get this to work? Any help would be much appreciated!
Contributor guide
Assessment
This issue has not been assessed yet.