Sam Hooke

Setting up Emscripten with CMake on Linux

Setting up Emscripten with CMake on Linux is largely the same as the earlier instructions for Setting up Emscripten with CMake in Git Bash on Windows 10. The steps about creating Python aliases can be skipped, since they only apply to Git Bash. The rest is then the same, since using Git Bash means we can use the Linux commands.

As a quick refresher, assuming you have a git repository with emsdk as a submodule, the steps for getting started on Linux are as follows:

Ensure the emsdk submodule is up-to-date §

git submodule update --init --recursive

Install and activate emsdk §

$ cd modules/emsdk/
$ ./emsdk install latest
$ ./emsdk activate latest
Resolving SDK alias 'latest' to '3.1.8'
Resolving SDK version '3.1.8' to 'sdk-releases-upstream-8c9e0a76ebed2c5e88a718d43e8b62452def3771-64bit'
Setting the following tools as active:

Next steps:
- To conveniently access emsdk tools from the command line,
  consider adding the following directories to your PATH:
- This can be done for the current shell by running:
    source "/home/sam/projects/MyProject/modules/emsdk/"
- Configure emsdk in your shell startup scripts by running:
    echo 'source "/home/sam/projects/MyProject/modules/emsdk/"' >> $HOME/.bash_profile

Perform the build §

As before, each time you open a new shell, you will need to source ./ so that tools such as emcc and emcmake are on the path.

Then you can build the project as follows:

emcmake cmake -S . -B build-em
cmake --build build-em

These are rough notes from whatever I was working on, interested in or thinking about at the time. They vary greatly in quality and length, but prove useful to me, and hopefully to you too!

← Previous: Setting up Emscripten with CMake in Git Bash on Windows 10
Next: Porting a simple SDL2 game to Emscripten →