emscripten-core / emscripten-core/emscripten

CMake SHARED library with Emscripten toolchain is not supported

Open
#17,804 3 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

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](https://user-images.githubusercontent.com/42750285/188650927-86da3eb7-edb1-47a6-9884-f336a86cedaa.png)

**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.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.