Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
Emscripten: how to use compiled C++ code via import/require

C++ source (app.cpp):

#include <stdio.h>
#include <emscripten/bind.h>

using namespace emscripten;

float lerp(float a, float b, float t) {
    return (1 - t) * a + t * b;
}

EMSCRIPTEN_BINDINGS(my_module) {
    function("lerp", &lerp);
}

Perform command: emcc -lembind -o ../output/app.js app.cpp -s ENVIRONMENT=web

Then launch Webpack dev-server (entry point: bootstrap.js). bootstrap.js:

const app = require('./wasm/output/app.js');

And... how to use compiled code now? Official documentation examples show only <script> tag usage. It says, that code can be used as node module, but I didn't find any example. console.log(app) displays Object. app.lerp(1, 2, 0.5) or Module.lerp(1, 2, 0.5) return app.lerp / Module.lerp is not a function. Tried to add export default Module to the end of compiled .js file and use as ES6 import(...), console.log(app) says that Module is a function.

Tried to add -s MODULARIZE=1 flag, the same result.

How to use compiled C++ via import or require?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!