Actually I'm using GSL in my c++ program. I've referred to the emscripten documentation but got nothing. This is what I see in the documentation, which makes no sense:
# For example, consider the case where a project “project” uses a library “libstuff”:
# Compile libstuff to bitcode
./emconfigure ./configure
./emmake make
# Compile project to bitcode
./emconfigure ./configure
./emmake make
# Compile the library and code together to HTML
emcc project.bc libstuff.bc -o final.html
(Isn't there something wrong with the documentation?) And it says nothing about how to use the library in javascript.
Here's the problems I have:
Thanks in advance.
js can dynamically load an external C or C++ DLL file at runtime and utilize its API to perform some operations written inside it from a JavaScript program. This is basically how a Native Addon works in Node.
To build using Emscripten you need to replace gcc with emcc in your makefiles. This is done using emconfigure, which sets the appropriate environment variables like CXX (C++ compiler) and CC (the compiler).
Emscripten is an LLVM/Clang-based compiler that compiles C and C++ source code to WebAssembly (or to a subset of JavaScript known as asm. js, its original compilation target before the advent of WebAssembly in 2017), primarily for execution in web browsers.
Embind is used to bind C++ functions and classes to JavaScript, so that the compiled code can be used in a natural way by “normal” JavaScript. Embind also supports calling JavaScript classes from C++. Embind has support for binding most C++ constructs, including those introduced in C++11 and C++14.
You will need access to the C/C++ source code of the third party library and compile it using Emscripten before you can link with it in your program.
Once you have compiled the third party library with Emscripten, you can now statically link with it and use it normally in your C/C++ program, which also needs to be built with Emscripten.
If you don't have your own C/C++ program, Emscripten 1.32.2 now supports building dynamic libraries into Javascript modules that you can use on your web page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With