# Issues I encountered while compiling with the vtk-wasm-sdk Docker.

**URL:** https://discourse.vtk.org/t/issues-i-encountered-while-compiling-with-the-vtk-wasm-sdk-docker/14322
**Category:** Support
**Tags:** webgpu, vtkwasm
**Created:** [July 30, 2024, 7:26am UTC](https://discourse.vtk.org/t/issues-i-encountered-while-compiling-with-the-vtk-wasm-sdk-docker/14322 "2024-07-30T07:26:16Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Behtgod](https://discourse.vtk.org/user_avatar/discourse.vtk.org/behtgod/32/9124_2.png) [@Behtgod](https://discourse.vtk.org/u/Behtgod)
#### Post date: [July 30, 2024, 7:26am UTC](https://discourse.vtk.org/t/issues-i-encountered-while-compiling-with-the-vtk-wasm-sdk-docker/14322/1 "2024-07-30T07:26:16Z")

</div>

When I used the Docker image of kitware/vtk-wasm-sdk, I encountered various problems.  
I followed the `Usage` on [DockerHub](https://hub.docker.com/r/kitware/vtk-wasm-sdk), downloaded the examples, and then proceeded to compile them.  
I am using the Windows platform, and the compilation script is like this:

```auto
$erroractionpreference = "stop"

$sdk_version="wasm32-v9.3.1-3657-gfd3dc37e8e-20240728"
$sdk_image="kitware/vtk-wasm-sdk"
$sdk_config="Release"

$sdk_dir="/VTK-install/$sdk_config/lib/cmake/vtk"

docker run `
    --rm `
    -v"$pwd/Cone":/Cone `
    ${sdk_image}:${sdk_version} `
    emcmake cmake -GNinja -S /Cone -B /Cone/build -DCMAKE_BUILD_TYPE="$sdk_config" -DVTK_DIR="$sdk_dir" # -DCMAKE_C_FLAGS=MEMORY64 -DCMAKE_CXX_FLAGS=MEMORY64

docker run `
    --rm `
    -v"$pwd/Cone":/Cone `
    ${sdk_image}:${sdk_version} `
    cmake --build /Cone/build

```

I used images with tag above:  
wasm32-v9.3.1-3657-gfd3dc37e8e-20240728  
wasm64-threads-v9.3.1-3657-gfd3dc37e8e-20240728  
wasm32-threads-v9.3.1-3657-gfd3dc37e8e-20240728  
wasm64-v9.3.1-3657-gfd3dc37e8e-20240728

`wasm32-v9.3.1-3657-gfd3dc37e8e-20240728` is works,but others failed.(Added `-DCMAKE_C_FLAGS=MEMORY64 -DCMAKE_CXX_FLAGS=MEMORY64` at 64-bit)

the log is:

```auto
configure: cmake -GNinja -S /Cone -B /Cone/build -DCMAKE_BUILD_TYPE=Release -DVTK_DIR=/VTK-install/Release/lib/cmake/vtk -DCMAKE_C_FLAGS=MEMORY64 -DCMAKE_CXX_FLAGS=MEMORY64 -DCMAKE_CROSSCOMPILING_EMULATOR=/emsdk/node/16.20.0_64bit/bin/node
-- Found OpenGL: /emsdk/upstream/emscripten/cache/sysroot/include found components: GLES3 
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - no
-- Could NOT find Threads (missing: Threads_FOUND)
-- Could NOT find Threads (missing: Threads_FOUND)
-- Configuring done (9.1s)
CMake Error at /VTK-install/Release/lib/cmake/vtk/VTK-targets.cmake:195 (set_target_properties):
  The link interface of target "VTK::CommonCore" contains:

    Threads::Threads

  but the target was not found. Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  /VTK-install/Release/lib/cmake/vtk/vtk-config.cmake:151 (include)
  CMakeLists.txt:17 (find_package)

CMake Error at /VTK-install/Release/lib/cmake/vtk/VTK-targets.cmake:384 (set_target_properties):
  The link interface of target "VTK::CommonSystem" contains:

    Threads::Threads

  but the target was not found. Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  /VTK-install/Release/lib/cmake/vtk/vtk-config.cmake:151 (include)
  CMakeLists.txt:17 (find_package)

-- Generating done (0.1s)
CMake Generate step failed. Build files cannot be regenerated correctly.
emcmake: error: 'cmake -GNinja -S /Cone -B /Cone/build -DCMAKE_BUILD_TYPE=Release -DVTK_DIR=/VTK-install/Release/lib/cmake/vtk -DCMAKE_C_FLAGS=MEMORY64 -DCMAKE_CXX_FLAGS=MEMORY64 -DCMAKE_CROSSCOMPILING_EMULATOR=/emsdk/node/16.20.0_64bit/bin/node' failed (returned 1)
ninja: error: loading 'build.ninja': No such file or directory

```

What is the problem, and how can it be resolved?

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [July 30, 2024, 12:47pm UTC](https://discourse.vtk.org/t/issues-i-encountered-while-compiling-with-the-vtk-wasm-sdk-docker/14322/2 "2024-07-30T12:47:53Z")

</div>

Hello @Behtgod!

That `Cone` example does not automatically enable threads. If you’re developing a threaded VTK wasm application, please see the unit test’s [vtk-wasm-sdk/.gitlab/ci/docker/tests/basic/CMakeLists.txt](https://gitlab.kitware.com/vtk/vtk-wasm-sdk/-/blob/main/.gitlab/ci/docker/tests/basic/CMakeLists.txt?ref_type=heads) for how to manage threads and 32/64 bit. That unit test is built and run for all images as a sanity check before they are published to dockerhub.

If you still want to run the Cone example with threads or 64-bit, you will need to correctly define the C/Cxx compiler flags and static/exe linker flags so that Emscripten compiler works.

> [@Behtgod](#):
>
> (Added `-DCMAKE_C_FLAGS=MEMORY64 -DCMAKE_CXX_FLAGS=MEMORY64` at 64-bit)

That memory flag is incomplete. Emscripten settings are specified using an `-s` prefix. Emscripten documents all settings here [Emscripten Compiler Settings — Emscripten 3.1.65-git (dev) documentation](https://emscripten.org/docs/tools_reference/settings_reference.html?highlight=settings#emscripten-compiler-settings)

As a general rule for any WebAssembly application built using Emscripten, here’s an unofficial table of the CMake flags required when targetting diffferent combinations of 32/64 bit with/without threads.

| Architecture | CMAKE\_C\_FLAGS | CMAKE\_CXX\_FLAGS | CMAKE\_EXE\_LINKER\_FLAGS | CMAKE\_STATIC\_LINKER\_FLAGS |
| --- | --- | --- | --- | --- |
| `32` | | | | |
| `64` | “-sMEMORY64=1” | “-sMEMORY64=1” | “-sMEMORY64=1” | “-sMEMORY64=1” |
| `32+threads` | “-pthread” | “-pthread” | “-pthread” | “-pthread” |
| `64+threads` | “-sMEMORY64=1 -pthread” | “-sMEMORY64=1 -pthread” | “-sMEMORY64=1 -pthread” | “-sMEMORY64=1 -pthread” |

---

<div class="post-metadata">

### Author: ![Behtgod](https://discourse.vtk.org/user_avatar/discourse.vtk.org/behtgod/32/9124_2.png) [@Behtgod](https://discourse.vtk.org/u/Behtgod)
#### Post date: [July 31, 2024, 6:22am UTC](https://discourse.vtk.org/t/issues-i-encountered-while-compiling-with-the-vtk-wasm-sdk-docker/14322/3 "2024-07-31T06:22:22Z")

</div>

Thank you @jaswantp.  
I modified CmakeLists and the compilation script, like above:

```auto
cmake_minimum_required(VERSION 3.13)
project(Cone)

# -----------------------------------------------------------------------------
# EMSCRIPTEN only
# -----------------------------------------------------------------------------

if (NOT EMSCRIPTEN)
  message("Skipping example: This needs to run inside an Emscripten build environment")
  return ()
endif ()

# -----------------------------------------------------------------------------
# Handle VTK dependency
# -----------------------------------------------------------------------------

find_package(Threads REQUIRED)

find_package(VTK
  COMPONENTS
    FiltersSources # VTK pipeline
    InteractionStyle # Mouse handling
    RenderingOpenGL2 # For Rendering
    RenderingUI # For SDL2 Window
)

if (NOT VTK_FOUND)
  message("Skipping example: ${VTK_NOT_FOUND_MESSAGE}")
  return ()
endif ()

# -----------------------------------------------------------------------------
# Compile example code
# -----------------------------------------------------------------------------

add_executable(Cone Cone.cxx)

target_link_libraries(Cone
  PRIVATE
    VTK::FiltersSources
    VTK::InteractionStyle
    VTK::RenderingOpenGL2
    VTK::RenderingUI
)

# -----------------------------------------------------------------------------
# WebAssembly build options
# -----------------------------------------------------------------------------
set(emscripten_link_options)
set(emscripten_compile_options)

list(APPEND emscripten_link_options
  "SHELL:-s WASM=1"
)

set(emscripten_debug_options)
set(DEBUGINFO "PROFILE" CACHE STRING "Type of debug info")
set_property(CACHE DEBUGINFO PROPERTY
  STRINGS
    NONE # -g0
    READABLE_JS # -g1
    PROFILE # -g2
    DEBUG_NATIVE # -g3
)

if(DEBUGINFO STREQUAL "NONE")
  list(APPEND emscripten_debug_options
    "-g0"
  )
elseif(DEBUGINFO STREQUAL "READABLE_JS")
  list(APPEND emscripten_debug_options
    "-g1"
  )
  list(APPEND emscripten_link_options
    "SHELL:-s DEMANGLE_SUPPORT=1"
  )
elseif(DEBUGINFO STREQUAL "PROFILE")
  list(APPEND emscripten_debug_options
    "-g2"
  )
  list(APPEND emscripten_link_options
    "SHELL:-s DEMANGLE_SUPPORT=1"
  )
elseif(DEBUGINFO STREQUAL "DEBUG_NATIVE")
  list(APPEND emscripten_debug_options
    "-g3"
  )
  list(APPEND emscripten_link_options
    "SHELL:-s ASSERTIONS=1"
    "SHELL:-s DEMANGLE_SUPPORT=1"
  )
endif()

# -----------------------------------------------------------------------------
# Build options
# -----------------------------------------------------------------------------
set(emscripten_optimizations)
set(OPTIMIZE "SMALLEST_WITH_CLOSURE" CACHE STRING "Emscripten optimization")
set_property(CACHE OPTIMIZE PROPERTY
  STRINGS
    NO_OPTIMIZATION # -O0
    LITTLE # -O1
    MORE # -O2
    BEST # -O3
    SMALL # -Os
    SMALLEST # -Oz
    SMALLEST_WITH_CLOSURE # -Oz --closure 1
)

if(OPTIMIZE STREQUAL "NO_OPTIMIZATION")
  list(APPEND emscripten_optimizations
    "-O0"
  )
elseif(OPTIMIZE STREQUAL "LITTLE")
  list(APPEND emscripten_optimizations
    "-O1"
  )
elseif(OPTIMIZE STREQUAL "MORE")
  list(APPEND emscripten_optimizations
    "-O2"
  )
elseif(OPTIMIZE STREQUAL "BEST")
  list(APPEND emscripten_optimizations
    "-O3"
  )
elseif(OPTIMIZE STREQUAL "SMALL")
  list(APPEND emscripten_optimizations
    "-Os"
  )
elseif(OPTIMIZE STREQUAL "SMALLEST")
  list(APPEND emscripten_optimizations
    "-Oz"
  )
elseif(OPTIMIZE STREQUAL "SMALLEST_WITH_CLOSURE")
  list(APPEND emscripten_optimizations
    "-Oz"
  )
  list(APPEND emscripten_link_options
    "--closure 1"
  )
endif()

target_compile_options(Cone
  PUBLIC
    ${emscripten_compile_options}
    ${emscripten_optimizations}
    ${emscripten_debug_options}
)

target_link_options(Cone
  PUBLIC
    ${emscripten_link_options}
    ${emscripten_optimizations}
    ${emscripten_debug_options}
)

### ---------- according vtk-wasm-sdk/.gitlab/ci/docker/tests/basic/CMakeLists.txt -------
target_compile_options(Cone PRIVATE "-sMEMORY64" "-Wno-experimental")
target_link_options(Cone PRIVATE "-sMEMORY64" "-Wno-experimental" "-sMAXIMUM_MEMORY=16GB")
target_compile_options(Cone PRIVATE "-pthread")
target_link_options(Cone PRIVATE "-pthread")
### -------------------------------------------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# VTK modules initialization
# -----------------------------------------------------------------------------

vtk_module_autoinit(
  TARGETS Cone
  MODULES ${VTK_LIBRARIES}
)

# -----------------------------------------------------------------------------
# Copy HTML to build directory
# -----------------------------------------------------------------------------

add_custom_command(
  TARGET Cone
  POST_BUILD
  COMMAND
    ${CMAKE_COMMAND} -E copy_if_different
      "${CMAKE_CURRENT_SOURCE_DIR}/index.html"
      $<TARGET_FILE_DIR:Cone>
)

```

```auto
$erroractionpreference = "stop"

$sdk_version="wasm64-threads-v9.3.1-3657-gfd3dc37e8e-20240728"

$sdk_image="kitware/vtk-wasm-sdk"
$sdk_config="Release"

$sdk_dir="/VTK-install/$sdk_config/lib/cmake/vtk"

docker run `
    --rm `
    -v"$pwd/Cone":/Cone `
    ${sdk_image}:${sdk_version} `
    emcmake cmake -GNinja -S /Cone -B /Cone/build -DCMAKE_BUILD_TYPE="$sdk_config" `
    -DVTK_DIR="$sdk_dir" `
# ------------------ add as the table -----------------------------
    -DCMAKE_C_FLAGS="-sMEMORY64=1 -pthread" `
    -DCMAKE_CXX_FLAGS="-sMEMORY64=1 -pthread" `
    -DCMAKE_EXE_LINKER_FLAGS="-sMEMORY64=1 -pthread" `
    -DCMAKE_STATIC_LINKER_FLAGS="-sMEMORY64=1 -pthread"

docker run `
    --rm `
    -v"$pwd/Cone":/Cone `
    ${sdk_image}:${sdk_version} `
    cmake --build /Cone/build

```

then compilation is completed.  
But, when I tried to run the example, show nothing and output error in console:

```auto
Cone.js:313 Uncaught ReferenceError: SharedArrayBuffer is not defined
    at Cone.js:313:40
:8080/favicon.ico:1 
        
        
       Failed to load resource: the server responded with a status of 404 (File not found)

```

What’s the issue? Have any suggestions?

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 1, 2024, 6:37pm UTC](https://discourse.vtk.org/t/issues-i-encountered-while-compiling-with-the-vtk-wasm-sdk-docker/14322/4 "2024-08-01T18:37:05Z")

</div>

WebAssembly uses `SharedArrayBuffer` instead of `ArrayBuffer` to share memory with threads. I assume you started a basic HTTP server.

> [@Behtgod](#):
>
> ```auto
> Cone.js:313 Uncaught ReferenceError: SharedArrayBuffer is not defined
> at Cone.js:313:40
> :8080/favicon.ico:1 
> 
> ```

You are getting this error because `SharedArrayBuffer` can pose security issues when used maliciously. As a safe measure, browsers require certain cross-origin configuration for security purpose. Try this script instead [Local HTTP server with COEP+COOP enabled for SharedArrayBuffer · GitHub](https://gist.github.com/pezcode/d51926bdbadcbd4f22f5a5d2fb8e0394)

---

<div class="post-metadata">

### Author: ![Behtgod](https://discourse.vtk.org/user_avatar/discourse.vtk.org/behtgod/32/9124_2.png) [@Behtgod](https://discourse.vtk.org/u/Behtgod)
#### Post date: [August 5, 2024, 10:05am UTC](https://discourse.vtk.org/t/issues-i-encountered-while-compiling-with-the-vtk-wasm-sdk-docker/14322/5 "2024-08-05T10:05:44Z")

</div>

Thank you! @jaswantp  
Another question, I tried build the example [vtkWasmBenchmarks](https://github.com/Kitware/vtkWasmBenchmarks) in the [blog](https://www.kitware.com/faster-rendering-of-large-number-of-actors-in-vtk-with-webgpu/) by docker image with tag `wasm32-v9.3.1-3657-gfd3dc37e8e-20240728`.  
But compile failed, the cmake error is:

```auto
  Found package configuration file:

    /VTK-install/Release/lib/cmake/vtk/vtk-config.cmake

  but it set VTK_FOUND to FALSE so package "VTK" is considered to be NOT
  FOUND. Reason given by package:

  Could not find the VTK package with the following required components:
  RenderingWebGPU.

```

I tried docker image with tag `v9.3.0-2490-g97c85d6930-202404010`, it’s ok.

How can I fix it?

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [August 5, 2024, 5:11pm UTC](https://discourse.vtk.org/t/issues-i-encountered-while-compiling-with-the-vtk-wasm-sdk-docker/14322/6 "2024-08-05T17:11:54Z")

</div>

The webgpu module is being worked upon right now, so until things have stabilized, please use the 20240410 docker image.

---

<div class="post-metadata">

### Author: ![hjxy2012](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hjxy2012/32/9334_2.png) [@hjxy2012](https://discourse.vtk.org/u/hjxy2012)
#### Post date: [October 8, 2024, 7:11am UTC](https://discourse.vtk.org/t/issues-i-encountered-while-compiling-with-the-vtk-wasm-sdk-docker/14322/7 "2024-10-08T07:11:15Z")

</div>

Hello everyone. I tried the same shell script and CMakeLists.txt as Behtgod.  
The sdk\_version was “_wasm64-threads-v9.3.1-4443-g80d5d9f8cd-20241005_” in my case.

And after the Cone.wasm and Cone.js were generated, I started the http server with “python server-cross-origin.py 4001”. When I opened the link “localhost:4001”, I got the following errors:  
1）wasm streaming compile failed: CompileError: WebAssembly.instantiateStreaming(): invalid memory limits flags 0x7 (enable with --experimental-wasm-memory64) @+4135  
2）falling back to ArrayBuffer instantiation  
…

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [October 8, 2024, 1:29pm UTC](https://discourse.vtk.org/t/issues-i-encountered-while-compiling-with-the-vtk-wasm-sdk-docker/14322/8 "2024-10-08T13:29:04Z")

</div>

> [@hjxy2012](#):
>
> wasm streaming compile failed: CompileError: WebAssembly.instantiateStreaming(): invalid memory limits flags 0x7 (enable with --experimental-wasm-memory64) @+4135

Enable wasm64 support in your browser. Go to chrome://flags and search for memory64
