Questions tagged [emscripten]

Emscripten is an LLVM-to-JavaScript compiler. It takes LLVM bitcode - which can be generated from C/C++, using llvm-gcc or clang, or any other language that can be converted into LLVM - and compiles that into JavaScript, which can be run on the web (or anywhere else JavaScript can run).

Links to demos, tutorial, FAQ, etc: https://github.com/kripken/emscripten/wiki

Main project page: http://emscripten.org

1241 questions
13
votes
1 answer

How can I run an interactive program compiled with Emscripten in a web page?

I've got a simple program, say the following: #include int main() { char buf[100]; while (fgets(buf, sizeof(buf), stdin) != NULL) { printf("You typed: %s", buf); } } and I have compiled it using Emscripten: emcc -o…
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
13
votes
2 answers

"Assertion failed: you need to wait for the runtime to be ready" Error when calling a C function in JavaScript

I am trying out a simple example to call a C function compiled to .wasm with JavaScript. This is the counter.c file: #include int counter = 100; EMSCRIPTEN_KEEPALIVE int count() { counter += 1; return counter; } I…
Kilian Obermeier
  • 6,678
  • 4
  • 38
  • 50
13
votes
3 answers

Export all functions with Emscripten

I would like to use C source code in an easy way with JavaScript (using only free/libre software). So Emscripten seems to be a good option.…
user3818296
13
votes
1 answer

Minimal working example for emscripten webworker

I'm trying to build a basic webworker example in C++ with emscripten. The API looks very simple, but I can't get it working. I actually wanted to implement this functionality in my project, but after failing tried to make a minimal example and it…
Alexander
  • 1,299
  • 2
  • 12
  • 32
13
votes
1 answer

Emscripten: emmake generating .js files

According to the Emscripten Docs Make generates linked LLVM bitcode. It does not automatically generate JavaScript during linking because all the files must be compiled using the same optimizations and compiler options — and it makes sense to do…
Josiah
  • 3,008
  • 1
  • 34
  • 45
13
votes
2 answers

What "use asm" does exactly?

As far as I know, Asm.js is just a strict specification of JavaScript, it uses the JavaScript features and it's not a new language. For instance, instead of using var a = e;, it offers var a = e|0;. My question is, if asm.js is just a definition and…
Afshin Mehrabani
  • 33,262
  • 29
  • 136
  • 201
12
votes
4 answers

How do I read a user-specified file in an emscripten compiled library?

I'm currently working on a file parsing library in C with emscripten compile support. It takes a file path from the user where it reads the binary file and parses it. I understand that emscripten doesn't support direct loading of files, but instead…
Ryan LeFevre
  • 643
  • 4
  • 12
11
votes
2 answers

How load an emscripten generated module with es6 import?

I am trying to import a module generated with emscripten as a es6 module. I am trying with the basic example from emscripten doc. This is the command I am using to generate the js module from the C module: emcc example.cpp -o example.js -s…
Eturcim
  • 798
  • 8
  • 26
11
votes
2 answers

How to use WebAssembly from node.js?

I am currently working on a personal Node.js (>=8.0.0) project which requires me to call C subroutines (to improve execution time). I am trying to use WebAssembly to do this since I need my final code to be compatible when opened in a browser. I…
Cheran
  • 113
  • 2
  • 7
11
votes
3 answers

Emscripten canvas + jQuery - toggle focus

I have an HTML page roughly divided 30% - 70% into two vertical columns. The left column contains a chat feed (handled via Node and Socket.io), and the right column contains an emscripten-generated canvas (with the ID of canvas). The canvas contains…
MassivePenguin
  • 3,701
  • 4
  • 24
  • 46
11
votes
1 answer

Creating web worker from Rust with Emscripten target

I'm trying to create a web worker from Rust, calling a function in the worker file and passing some data to the main thread. main.rs mod externs; extern crate libc; fn main() { println!("starting worker"); let worker =…
Afshin Mehrabani
  • 33,262
  • 29
  • 136
  • 201
11
votes
1 answer

How do I compile C++ to JavaScript in a browser?

I'm aware of Emscripten and LLVM, but neither are written in JavaScript intended for a browser. As far as I can tell, the tools exist, but they haven't been put together, but I could very well be missing some key factor that makes it very difficult…
Sophie McCarrell
  • 2,831
  • 8
  • 31
  • 64
11
votes
1 answer

How to add an own struct_info.json? (emscripten)

I would like to port a C library. There is a really short tutorial about it here: Interacting with code I need to create a struct using javascript, and return a pointer to it. I looked into the libraries, which are already ported. My code looks like…
Iter Ator
  • 8,226
  • 20
  • 73
  • 164
11
votes
4 answers

How to make emcc work?

When I tried to use emcc to compile a C code into Javascript, I received the following error: emcc tests/hello_world.c CRITICAL root: fastcomp in use, but LLVM has not been built with the JavaScript backend as a target, llc…
Adam Lee
  • 24,710
  • 51
  • 156
  • 236
11
votes
1 answer

What is the purpose of this eval conditional?

I was browsing through the source code here: http://js-dos.com/games/doom2.exe.html and noticed a few things: if (typeof Module === 'undefined') { Module = eval('(function() {try { return Module || {} } catch(e) { return {} }})()'); } The…
user1585455
1 2
3
82 83