When I used the Docker image of kitware/vtk-wasm-sdk, I encountered various problems.
I followed the Usage on DockerHub, downloaded the examples, and then proceeded to compile them.
I am using the Windows platform, and the compilation script is like this:
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:
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
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 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.
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.
then compilation is completed.
But, when I tried to run the example, show nothing and output error in console:
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)
WebAssembly uses SharedArrayBuffer instead of ArrayBuffer to share memory with threads. I assume you started a basic HTTP server.
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
Thank you! @jaswantp
Another question, I tried build the example vtkWasmBenchmarks in the blog by docker image with tag wasm32-v9.3.1-3657-gfd3dc37e8e-20240728.
But compile failed, the cmake error is:
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.
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
…