I have compiled 2 c functions to wasm and when I try to use them in a simple website I get this error in the console ReferenceError: Can't find variable: Module
:
My c Code
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "argon2.h"
#include "emscripten.h"
EMSCRIPTEN_KEEPALIVE
const int secret(const int key, const int iters)
{
...
}
EMSCRIPTEN_KEEPALIVE
const char *argon_hash(const char *SALT, const char *PWD, const uint32_t HASHLEN, const uint32_t LOWERS,
const uint32_t UPPERS, const uint32_t NUMS, const uint32_t SPCLS)
{
...
}
Here is my compilation script
emcc -std=gnu99 -O3 -flto --closure 1
-I./argon2/include -I./argon2/src -DARGON2_NO_THREADS=1
./argon2/src/argon2.c ./argon2/src/core.c ./argon2/src/blake2/blake2b.c
./argon2/src/thread.c ./argon2/src/encoding.c ./argon2/src/ref.c
-s INLINING_LIMIT=1 -s NO_EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1 -s FILESYSTEM=0
-s EXPORTED_FUNCTIONS='["_secret", "_argon_hash"]' -s EXPORTED_RUNTIME_METHODS='["cwrap", "ccall"]'
argon2-web.c -o argon2-web.js
This generates argon2-web.js as well as argon2-web.wasm
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Simple template</title>
<script src="./argon2-web.js"></script>
</head>
<body>
<script src="./web_test.js"></script>
<p>Hello World</p>
</body>
</html>
web_test.js
secret = Module.cwrap("secret", "number", [ "number", "number" ]);
argon_hash =
Module.cwrap("argon_hash", "string", [ "string", "string", "number", "number", "number", "number", "number" ]);
function makePass(salt, pass, len = 16, key = 1, lowers = 1, uppers = 1, numerics = 1, specials = 1)
{
var slt_sct = salt.concat(secret(key, len).toString());
var hash = argon_hash(slt_sct, pass, len, lowers, uppers, numerics, specials);
return hash;
}
var pass = makePass('The Salt', 'The Password');
console.log(pass)
document.body.innerHTML = '<h1>The Password is ' + pass + '</h1>'
question from:
https://stackoverflow.com/questions/65926220/why-cant-this-website-find-the-module-javascript-object