Skip to content

CMake SHARED library with Emscripten toolchain is not supported #17804

@Hazardu

Description

@Hazardu

Im using CMAKE and Visual Studio 2022 as the generator with the following CMakeLists.txt


set(SOURCE_FILES window.cpp callbacks.cpp main.cpp) 

set(RENDERER_FILES renderer.cpp renderer.h)

add_library(Renderer SHARED ${RENDERER_FILES})

add_executable(EmscriptenHTML5 ${SOURCE_FILES})

set_target_properties(Renderer PROPERTIES 
	COMPILE_FLAGS "-fPIC"
    LINK_FLAGS "-sSIDE_MODULE=1 -sUSE_WEBGL2=1 -sFULL_ES3=1 -sWASM=1 -sWASM_BIGINT -sMIN_WEBGL_VERSION=2 -sASYNCIFY -sEXPORT_ALL=1 --no-entry -fPIC"
    SUFFIX ".wasm"
)
set_target_properties(EmscriptenHTML5 PROPERTIES 
	COMPILE_FLAGS "-fPIC"
    LINK_FLAGS "-sMAIN_MODULE=1 -sUSE_WEBGL2=1 -sFULL_ES3=1 -sWASM=1 -sWASM_BIGINT -sMIN_WEBGL_VERSION=2 -sASYNCIFY -fPIC" 
    SUFFIX ".html"
)
add_dependencies(EmscriptenHTML5 Renderer)
target_link_libraries(EmscriptenHTML5 Renderer)

Toolchain file is defined in CMakeSettings.json (set to emscripten).
I want to use dynamic linking at loadtime.

The resulting Renderer shared library project is treated and compiled as a static library.
In Visual Studio opening a CMake project the Solution Explorer displays the following
image

Verbose output commands:
The verbose output command for linking Renderer uses emar

  [5/6] cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E rm -f libRenderer.wasm && D:\Hazard\Repos\emsdk\upstream\emscripten\emar.bat qc libRenderer.wasm  CMakeFiles/Renderer.dir/renderer.cpp.o && D:\Hazard\Repos\emsdk\upstream\emscripten\emranlib.bat libRenderer.wasm && cd ."

Version of emscripten/emsdk:
3.1.20

While configuring CMAKE this dev warning is displayed

  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.
This warning is for project developers.  Use -Wno-dev to suppress it.

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