Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
Calling C function from JavaScript using emscripten

I am currently trying to compile C to wasm and use it on a website. But I have had zero luck so far.

What I currently have is the following C source file:

#include <emscripten.h>

EMSCRIPTEN_KEEPALIVE
int sum(int a, int b) {
  return a + b;
}

I compile it using the following emscripten command:

emcc test.c -o test.js -s EXPORTED_FUNCTIONS="['_sum']" -sMODULARIZE

This produces test.wasm and test.js.

Then, I have the following html code:

<html>
<!--...-->
<body>
  <script type="module">
    var _import = import('test.js');
    _import.then((instance) => {
      console.log(instance._sum());
    });
  </script>
</body>
</html>

When I start up a development server, I get the following error in the console:

Uncaught (in promise) TypeError: instance._sum is not a function
    <anonymous> http://localhost:8000/:7
    promise callback* http://localhost:8000/:6

I also tried instance.sum and instance.ccall('sum'), both with the same result.

I have no clue at this point what I am doing wrong.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda