# C++ Web Assembly
# Sources
# Seeing WebAssembly in Action
# Setting Up Your Toolchain
The tool used to compile C++ to JavaScript is called Emscripten.
# Installing Emscripten
# Get the emsdk repo
git clone https://github.com/emscripten-core/emsdk.git
# Enter that directory
cd emsdk
# Fetch the latest version of the emsdk (not needed the first time you clone)
git pull
# Download and install the latest SDK tools.
./emsdk install latest --permanent
# Make the "latest" SDK "active" for the current user. (writes .emscripten file)
./emsdk activate latest
# Activate PATH and other environment variables in the current terminal
source ./emsdk_env.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Test:
emcc -v
1
Output:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.9 (54675bac246e84ca024c182e477665d21fe2e2f7)
clang version 15.0.0 (https://github.com/llvm/llvm-project faef447e72a5c63dfb12bb7b02d44c3c916d31cd)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\Users\Thiago Souto\Documents\COURSES\C++\WebAssembly\Emscripten\emsdk\upstream\bin
1
2
3
4
5
2
3
4
5
or
emcc --version
1
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.9 (54675bac246e84ca024c182e477665d21fe2e2f7)
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.
1
2
3
4
2
3
4
Running a C++ Hello World
Thiago Souto@MSI MINGW64 ~/Documents/COURSES/C++/WebAssembly/C++ helloWorld
$ emcc main.cpp -o test.html --emrun
Thiago Souto@MSI MINGW64 ~/Documents/COURSES/C++/WebAssembly/C++ helloWorld
$ emrun test.html
Hello, World!
1
2
3
4
5
6
7
2
3
4
5
6
7