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
17
votes
2 answers

Bundle Wasm + JS file into one using webpack

I am currently using Emscripten to compile our C++ Code into Wasm. By doing so I output two files *.js and *.wasm. Later I use our implementation to write more Javascript code on top of that which leads us to 3 files: index.js wasmFile.js …
civic.sir
  • 400
  • 1
  • 9
  • 26
17
votes
3 answers

How can I conditionally compile code for emscripten?

Working with a codebase which supports building for multiple Operating Systems, it is only sensible, where modifications for Emscripten are required, to integrate them into the same codebase, with the assistance of conditional compilation to let it…
Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
16
votes
1 answer

How are go channels and goroutines translated to webassembly?

Have been programming in Go from quite some time, and started looking into WebAssembly lately. While most of the things are straightforward, have a question around translating some of the Go specific constructs like channels and goroutines to wasm.…
Sam
  • 4,302
  • 12
  • 40
  • 74
16
votes
2 answers

How to use Emscripten compiled JavaScript within React / React Native

I'm currently using Emscripten to compile a basic C function into JavaScript to use within a React Native project. However, when I import Module from inside React code, the Module object is empty. This occurs in both React and React Native…
Chris Poe
  • 678
  • 6
  • 15
16
votes
3 answers

Providing stdin to an emscripten HTML program?

I have a C program that takes one argument (a char array / string) via command line and also reads from stdin. I've compiled it to JavaScript using emscripten. This was successful and I can run it just like the normal C program using node.js: emcc…
turbo
  • 1,233
  • 14
  • 36
16
votes
3 answers

Passing a C++ function to a javascript function in emscripten

I am learning about emscripten and trying to understand it better. As far as I understand the use-case it was mostly designed for is to port existing C/C++-code to a web client (browser) and calling C/C++ code from JavaScript. But I am wondering…
Markus Pilman
  • 3,104
  • 3
  • 22
  • 31
15
votes
1 answer

CMake project for Emscripten

I want to make CMake and Emscripten friends. Didn't find more or less informative documentation on the Emscripten project website, but they provide CMake toolchain file so I think it should be possible. So far very basic compilation without advanced…
Alexander
  • 1,299
  • 2
  • 12
  • 32
14
votes
3 answers

HmacSHA256 in WebAssembly compiled with Emscripten

I'm trying to implement JWT token (encoding only) in WebAssembly, the goal is to have a very light weight wasm module. As a web developer my C knowledge is limited. For now I've implemented the following function (ported from JS) to encode url-safe…
Roni Gadot
  • 437
  • 2
  • 19
  • 30
14
votes
2 answers

WebAssembly calling JavaScript methods from wasm i.e. within C++ code

I was playing with WebAssembly and so far and I was able to manage emscripten compile my test C++ project to wasm file em++ provides me 2 files i.e. mainTest.js mainTest.wasm When I load mainTest.js in my html page then I get a JavaScript object…
Tito
  • 2,234
  • 6
  • 31
  • 65
14
votes
1 answer

Passing a JavaScript array of strings to a C function with Emscripten

I'm new to WebAssembly and Emscripten and am trying to pass an array of strings in JavaScript to a C function for further processing with Module.cwrap(...). Ideally I'd also like to return an array of strings back to JavaScript from C. Below is some…
Brannon
  • 1,286
  • 2
  • 21
  • 36
14
votes
2 answers

WebAssembly Link Error: import object field 'DYNAMICTOP_PTR' is not a Number

The following C file is compiled to wasm with emscripten: int counter = 100; int count() { counter += 1; return counter; } $ emcc counter.c -o counter.wasm -s WASM=1 -s SIDE_MODULE=1 With no issues. I then have webpack loading the wasm…
Maxime R.
  • 9,621
  • 7
  • 53
  • 59
14
votes
1 answer

Changing the default namespace 'Module' in emscripten

I am using emscripten to provide Javascript bindings for some libraries. Emsripten packages the code into a namespace (global var), called 'Module'. I want to change the naming so that I can use a name that reflects what the library is used for,…
Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
14
votes
4 answers

How to pass strings between C++ and javascript via emscripten

I am learning emscripten, and I can't even get the most basic string manipulation working, when passing strings between C++ and JS. For example, I would like to write a string length function. In C++: extern "C" int stringLen(std::string p) { …
tenfour
  • 36,141
  • 15
  • 83
  • 142
13
votes
1 answer

How to build a custom opencv.js with opencv_contrib

I would like to include xfeatures2D from opencv_contrib into opencv.js. I follow this documentation Build OpenCV.js. Everything is ok. I got a brand new opencv.js that I'm able to use in my html page, but it doesn't include the xfeatures2D module. I…
13
votes
2 answers

Could WASM be used to check integrity of a JS method?

I'm experimenting with webAssembly and trying to figure out a way of validating the integrity of a JS method used by the webAssembly module. For the purpose of the discussion, let's assume that the binary module is not hackable (I know it is not the…
Shlomi Schwartz
  • 8,693
  • 29
  • 109
  • 186
1
2
3
82 83