Document
WAMR on GitHubWAMR Blogs
  • WAMR Document Home Page
  • Basics
    • Introduction
      • WebAssembly
      • WAMR Project
      • Security Feature
    • Getting Started
      • Host Environment Preparation
      • Hello-world Program On Host
      • Docker Environment Preparation
      • Hello-world Program On Docker
      • Build And Run WASM Application
        • More Tools To Create WASM Application
  • WAMR In Practice
    • Tutorial
      • WAMR Running Modes
      • Build Tutorial
        • Build iwasm
        • Build wamrc
      • Language Embedding
        • C/C++
        • Python
        • Go
      • Debugging & IDE Support
        • WAMR Source Debugging With LLDB
        • VS Code Support
          • Enable Debugging In VS Code
          • Move LLDB Binaries
    • Advance Tutorial
      • Performance Test
        • PolyBench
        • CoreMark
        • Sightglass
        • JetStream2
      • Memory Usage Tunning
      • Application Framework
      • Remote Application Management
        • Example 1: Install/Uninstall WASM App Remotely
        • Example 2: IoT App Store Demo
      • WAMR Porting Guide
    • Features
      • Export Native APIs To WASM Applications
        • Example 1: Export C Functions to WASM
        • Example 2: Using "native-lib"
      • Multiple Modules As Dependencies
        • Multi-modules Example
      • Multi-thread, Pthread APIs And Thread Management
        • Multi-thread Example
      • Linux SGX(Intel Software Guard Extension) Support
      • Linux SGX Remote Attestation
      • XIP(Execution In Place) Support
      • Socket Support
        • Example: Use Socket Api in WAMR
      • Post-MVP Features
        • WASM C API
        • 128-bit SIMD
        • Reference Types
    • More Examples
      • File Interaction Of WASI
      • GUI Example
        • Littlevgl
        • LVGL
      • Same WASM Program Executing Concurrently
      • Build And Run Workload
    • User Case
  • Programmer's Manual
    • Programmer's Manual
      • C API Lists
  • Community
    • How To Contribute
    • WAMR On Github
    • WAMR Blogs
  • Appendix
    • Appendix A. Background Knowledge And Glossary Of Terms
    • Appendix B. WebAssembly Details
    • Appendix C. Complete WAMR Guide
Powered by GitBook
On this page
  • Use clang compiler
  • Using Docker
  1. Basics
  2. Getting Started
  3. Build And Run WASM Application

More Tools To Create WASM Application

PreviousBuild And Run WASM ApplicationNextTutorial

Last updated 2 years ago

Use clang compiler

The recommended method to build a WASM binary is to use clang compiler clang-8. You can refer to for the detailed instructions. Here are referenced steps to install clang-8 in Ubuntu 16.04 and Ubuntu 18.04.

(1) Add source to your system source list from llvm website

For Ubuntu 16.04, add the following lines to /etc/apt/sources.list:

deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial main
# 8
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main
# 9
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main

For Ubuntu 18.04, add the following lines to /etc/apt/sources.list:

# i386 not available
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic main
# 8
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main
# 9
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main

(2) Download and install clang-8 tool-chain using following commands:

sudo wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
# Fingerprint: 6084 F3CF 814B 57C1 CF12 EFD5 15CF 4D18 AF4F 7421
sudo apt-get update
sudo apt-get install llvm-8 lld-8 clang-8

(3) Create a soft link under /usr/bin:

cd /usr/bin
sudo ln -s wasm-ld-8 wasm-ld

(4) Use the clang-8 command below to build the WASM C source code into the WASM binary.

clang-8 --target=wasm32 -O3 \
        -z stack-size=4096 -Wl,--initial-memory=65536 \
        -Wl,--allow-undefined,--export=main \
        -Wl,--strip-all,--no-entry -nostdlib \
        -o test.wasm test.c

You will get test.wasm which is the WASM app binary.

Using Docker

Use the clang-8 command below to build the WASM C source code into the WASM binary.

clang-8 --target=wasm32 -O3 \
        -z stack-size=4096 -Wl,--initial-memory=65536 \
        -Wl,--allow-undefined,--export=main \
        -Wl,--strip-all,--no-entry -nostdlib \
        -o test.wasm test.c

You will get test.wasm which is the WASM app binary.

Another method availble is using . We assume you've already configured Docker (see Platform section above) and have a running interactive shell. Currently the Dockerfile only supports compiling apps with clang, with Emscripten planned for the future.

apt.llvm.org
Docker