Skip to content

SHARED / dynamic library with CMake #15276

Closed
@DerThorsten

Description

@DerThorsten

Hi,
I have a question wrt shared / dynamic linking.
While I can successful generated a shared library with emscripten when I use no build system with smth like

em++ -c -fpic package_a/a.cpp -s SIDE_MODULE=1 -s EXPORT_ALL=1  -s LLD_REPORT_UNDEFINED -Ipackage_a -shared -o liba.wasm

I cannot make cmake generate a shared / dynamic library.
I try to pass the required SIDE_MODULE flag via target_compile_options / target_link_options but I still get the error message that the the target platform does not support dynamic linking.

    add_library(${name} SHARED ${ALL_FILES})
    SET(EMS_OPTS "-s SIDE_MODULE=1 -shared -s EXPORT_ALL=1 ")
    target_compile_options(${name}  PUBLIC ${EMS_OPTS})
    target_link_options(${name}     PUBLIC ${EMS_OPTS})
  ADD_LIBRARY called with SHARED option but the target platform does not
  support dynamic linking.  Building a STATIC library instead.  This may lead
  to problems.

I know that static libraries are recommended but I try to compile LLVM / clang / cling itself for emscripten and I need support for dlopen.
When I compile everything with static linking I do not get support for dlopen and get error messages when I use the generated code.

Is there any minimal example how to generate shared libs from cmake?

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