SPiCa
SPiCa

Reputation: 447

How to compile c++ to javascript using emscripten while including third party libraries?

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:

  1. How to build a third party library into bitcode?
  2. How to use the library in javascript?

Thanks in advance.

Upvotes: 9

Views: 2079

Answers (1)

Erunehtar
Erunehtar

Reputation: 1693

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.

Upvotes: 2

Related Questions