Ubuntu: Fixing install wasm-bindgen-cli problem

Fixing Ubuntu wasm-bindgen-cli installation errors

The wasm-bindgen-cli is a command line tool that is used to generate JavaScript bindings for the WebAssembly modules. It was used in a previous tutorial on how to create and run a Wasm Rust module in a browser. I was using Windows when I wrote that article, but a few days ago, I went through the tutorial using Ubuntu 20.04 and encountered few errors when attempting to install wasm-bindgen-cli tool.

Note: This article was tested using rustc 1.67.0 (January 2023) on Ubuntu 20.04.

To install the wasm-bindgen-cli tool, we use the following command:

cargo install wasm-bindgen-cli
Note: In order to install the tool, we need to have Rust installed. For Linux, we install it by running the curl https://sh.rustup.rs -sSf | sh into the terminal. More information can be found on this page.

Aside from a bit lengthy installation process, I didn't have any other issues when using Windows, but on Ubuntu 20.04, I received two installation errors.

The linker `cc` not found error

The first error that appeared was related to the linker.

Compiling libc v0.2.139
error: linker `cc` not found
= note: No such file or directory (os error 2)

error: could not compile `libc` due to previous error
warning: build failed, waiting for other jobs to finish...
error: failed to compile `wasm-bindgen-cli v0.2.84`, intermediate artifacts can be found at ...

The solution was to install the build-essential package, which includes basic tools to compile other packages from the source code.

sudo apt-get update
sudo apt install build-essential

This fixed the linker error, but when I ran the wasm-bindgen-cli installation again, I got another error.

The "failed to run custom build command for openssl-sys" error

The exact error message displayed was as follows:

error: failed to run custom build command for `openssl-sys v0.9.80`

Caused by:
process didn't exit successfully: `/tmp/cargo-installbcXvkc/release/build/openssl-sys-972f5eb3ddbebfda/build-script-main` (exit status: 101)
--- stdout

And the solution here was first to install the libssl-dev package, which is a development library for OpenSSL.

sudo apt install libssl-dev

But this wasn't enough. I also needed to install the pkg-config package that is used to manage library dependencies.

sudo apt install pkg-config

If we now attempt the installation again, it should succeed. The last line of the installation process should display something like this:

Installed package `wasm-bindgen-cli v0.2.84` (executables `wasm-bindgen`, `wasm-bindgen-test-runner`, `wasm2es6js`)

We can verify that the installation was successful by checking the version of the tool:

wasm-bindgen --version


The wasm-bindgen-cli tool is part of the wasm-bindgen project, and we can use it to bind the wasm module with JavaScript. That way, we can run the wasm module from a browser for example. To successfully install the wasm-bindgen-cli tool on Ubuntu 20.04, we must first have Rust installed. We also need to have a few packages installed too. Those are build-essential, libssl-dev, and the pkg-config package.

Write a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.