Emscripten toolchain for macOS.
Included:
- Emscripten:
3.1.22 - LLVM:
15.0.1 - binaryen:
105 - NodeJS:
16.14.2
Install toolchain:
./install.sh /opt/localAfter installed, add emscripten to $PATH:
export PATH=/opt/local/emsdk/emscripten:$PATHRequried preinstall:
- Xcode or Command Line Tools For Xcode
- CMake
- Ninja
./build.shmain.c
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}Build main.c:
emcc main.c \
-s EXIT_RUNTIME=1 \
-o index.htmlTest:
python3 -m http.serverVisit http://127.0.0.1:8000/ , You will see Hello World! printed.
Build main.c with -Os option:
emcc -Os main.c -s EXIT_RUNTIME=1 -o index.htmlemcc --clear-cacheCMakeLists.txt
cmake_minimum_required(VERSION 3.10.2)
project(sample C)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
set(CXX_STANDARD 14)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release")
endif()
add_executable(sample main.c)
set_target_properties(sample PROPERTIES LINK_FLAGS "-s EXIT_RUNTIME=1")
Configure and Build:
emcmake cmake -S . -B build -G Ninja
emmake ninja -C build