Replies: 2 comments
-
Hi, Can you clarify what you are trying to do? (not how, but the eventual goal) In order to compile for the emscripten environment, after cloning the repository, you can do: ./dist-build/emscripten.sh --sumo Then you get a WebAssembly module that can be called from Javascript, as done in libsodium.js. I don't think you can just link emscripten generated modules like that, especially since instantiating the library requires waiting for a Javascript promise to complete. If you want to throw code written in C/C++ and link everything as a standalone module for Node, a better way is probably to compile for WASI. You get a regular library that you can link C/C++/Zig/Rust/etc. code to in order to build an application. |
Beta Was this translation helpful? Give feedback.
-
Hi, I solved the problem. I added to the cpp code: sodium_init() . Thanks and I am sorry for my mistake. |
Beta Was this translation helpful? Give feedback.
-
I build this simple code:
https://github.com/jkb77/test_js
using emcc :
emcc test.cpp -I <path_to libsodium-js-sumo>/include -L /lib/ -lsodium
and I get 2 files:
when I try to:
node a.out.js
I get:
/home/jakub/test/a.out.js:146
throw ex;
^
TypeError: Module.getRandomValue is not a function
at 14508 (/home/jakub/test/a.out.js:1704:36)
at _emscripten_asm_const_int (/home/jakub/test/a.out.js:1843:31)
at wasm-function[52]:0x1fb9
at wasm-function[53]:0x1fdd
at wasm-function[13]:0xdc7
at wasm-function[51]:0x1f8f
at /home/jakub/test/a.out.js:1523:22
at callMain (/home/jakub/test/a.out.js:5124:15)
at doRun (/home/jakub/test/a.out.js:5181:23)
at run (/home/jakub/test/a.out.js:5196:5)
node version is v12.22.5
I built libsodium:
https://github.com/jedisct1/libsodium
git clone https://github.com/jedisct1/libsodium --branch stable
cd libsodium
cp dist-build/emscripten.sh ~/libsodium/
./emscripten.sh --sumo
Beta Was this translation helpful? Give feedback.
All reactions