Skip to content

CMake shared libraries error: shared library dependency not found in library path #24195

Open
@donalffons

Description

@donalffons

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 (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:

# 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)
# 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions