12

I want to install the latest emscripten in ubuntu for playing with WebAssembly using the following command.

sudo apt-get install emscripten  

But it gives me the version 1.22.1 which is a version in 2014 and do not support WebAssembly compiling.

$ emcc --version
emcc (Emscripten GCC-like replacement) 1.22.1 ()
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Are there a simple guide for installing the latest emscripten in command line?

1
  • 1
    UPDATE 2022: sudo apt-get install emscripten works for me Dec 20, 2022 at 10:20

3 Answers 3

8

The installation instructions suggest: download emsdk-portable.tar.gz

Unzip it, then open a terminal and run:

# Fetch the latest registry of available tools.
./emsdk update

# Download and install the latest SDK tools.
./emsdk install latest

# Make the "latest" SDK "active"
./emsdk activate latest

see: http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#installation-instructions for more information

1
  • This doesn't seem to install emcc.
    – Cerin
    Sep 1, 2020 at 23:10
7

From the emscripten's doc page [ from the ground zero ]

1. Get the emsdk repo

git clone https://github.com/emscripten-core/emsdk.git

2. Enter that directory

cd emsdk

3. Download and install the latest SDK tools

./emsdk install latest

4. Make the "latest" SDK "active"

./emsdk activate latest

5. Activate PATH and other environment variables

source ./emsdk_env.sh

these variables are set for the current terminal, if you want to make it for everybody, so you can put into any terminal profile. Here they are:

The environment variables:

EMSDK = < path to emsdk dir >

EM_CONFIG = ~/.emscripten

EMSDK_NODE = < path to emsdk dir >/node/12.9.1_64bit/bin/node

6. Now just try it!

emcc
5

It is not enough to build a newer version of emscripten. You will also have to build LLVM yourself, as emscripten will complain about

CRITICAL:root:WebAssembly set as target, but LLVM has not been built with the WebAssembly backend

I got it running by following the tutorial on building LLVM at http://llvm.org/docs/GettingStarted.html and some hints from https://github.com/kripken/emscripten/wiki/New-WebAssembly-Backend

git clone http://llvm.org/git/llvm.git
git -C llvm/tools clone http://llvm.org/git/clang.git
git -C llvm/projects clone http://llvm.org/git/compiler-rt.git
git -C llvm/projects clone http://llvm.org/git/openmp.git
git -C llvm/projects clone http://llvm.org/git/libcxx.git
git -C llvm/projects clone http://llvm.org/git/libcxxabi.git
mkdir llvmbuild
cd llvmbuild
cmake -G "Unix Makefiles" \
      -DLLVM_ENABLE_PROJECTS="llvm/tools/clang;llvm/projects/libcxx;llvm/projects/libcxxabi" \
      -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly \
      -DCMAKE_BUILD_TYPE=Release \
      ../llvm
make all
cd ..

And then following the tutorial on building emscripten at http://webassembly.org/getting-started/developers-guide/

git clone https://github.com/juj/emsdk.git
cd emsdk
./emsdk install sdk-incoming-64bit binaryen-master-64bit
./emsdk activate sdk-incoming-64bit binaryen-master-64bit
source ./emsdk_env.sh
cd ..

# configure emscripten to use self-built LLVM
cat ~/.emscripten \
    | sed "s:LLVM_ROOT=[^\n]*:LLVM_ROOT='${PWD}/llvmbuild/bin':g" \
    > ~/.emscripten.tmp
mv ~/.emscripten ~/.emscripten.bak
mv ~/.emscripten.tmp ~/.emscripten
1
  • After that, I could compile a .cpp file to WebAssembly as described at webassembly.org/getting-started/developers-guide . Notice that the html file uses XmlHttpRequests, so it doesn't work through the file:// protocol, you have to load it via http:// or https://
    – Algoman
    Jun 21, 2017 at 11:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .