Logo
  • Introducing Emscripten
    • About Emscripten
      • Emscripten Toolchain
      • Porting code to use Emscripten
    • Community
      • Get in touch
      • Report a bug
      • Contribute
    • Open Source License
    • Release Notes
    • Talks and Publications
      • Presentations
      • Papers
      • Books
  • Getting Started
    • Download and install
      • Installation instructions using the emsdk (recommended)
        • Emsdk install targets
        • Platform-specific notes
      • Verifying the installation
      • Updating the SDK
      • Uninstalling the Emscripten SDK
      • Using the Docker image
      • Installation using unofficial packages
    • Emscripten Tutorial
      • First things first
      • Verifying Emscripten
      • Running Emscripten
      • Generating HTML
      • Using files
      • Optimizing code
      • Emscripten Test Suite and Benchmarks
      • General tips and next steps
    • Emscripten Test Suite
      • Setting up
      • Running tests
      • Skipping Tests
      • Running a bunch of random tests
      • Important Tests
      • Benchmarking
      • Debugging test failures
    • Bug Reporting
      • LLVM, wasm-ld, clang, Binaryen bugs
      • Site and documentation bugs
    • FAQ
      • How do I compile code?
      • Why do I get multiple errors building basic code and the tests?
      • I tried something: why doesn’t it work?
      • Do I need to change my build system to use Emscripten?
      • Why is code compilation slow?
      • Why does my code run slowly?
      • Why is my compiled code big?
      • Why does compiling code that works on another machine gives me errors?
      • How can I reduce startup time?
      • How do I run a local webserver for testing / why does my program stall in “Downloading…” or “Preparing…”?
      • What is “No WebAssembly support found. Build with -sWASM=0 to target JavaScript instead” or “no native wasm support detected”?
      • Why do I get machine type must be wasm32 or is not a valid input file during linking?
      • Why does my code fail to compile with an error message about inline assembly (or {"text":"asm"})?
      • Why does my HTML app hang?
      • How do I run an event loop?
      • Why doesn’t my SDL app work?
      • How do I link against system libraries like SDL, boost, etc.?
      • What are my options for audio playback?
      • How can my compiled program access files?
      • Why can’t my code access a file in the same directory?
      • How can I tell when the page is fully loaded and it is safe to call compiled functions?
      • What does “exiting the runtime” mean? Why don’t atexit()s run?
      • Why do functions in my C/C++ source code vanish when I compile to JavaScript, and/or I get No functions to process?
      • Why is the File System API is not available when I build with closure?
      • Why does my code break and gives odd errors when using -O2 --closure 1?
      • Why do I get TypeError: Module.someThing is not a function?
      • Why does Runtime no longer exist? Why do I get an error trying to access Runtime.someThing?
      • Why do I get a NameError or a problem occurred in evaluating content after a "-s" when I use a -s option?
      • How do I specify -s options in a CMake project?
      • Why do I get a Python SyntaxError: invalid syntax on file=.. or on a string starting with f'..'?
      • Why does running LLVM bitcode generated by emcc through lli break with errors about impure_ptr?
      • Why do I get a stack size error when optimizing: RangeError: Maximum call stack size exceeded or similar?
      • Why do I get error: cannot compile this aggregate va_arg expression yet and it says compiler frontend failed to generate LLVM bitcode, halting afterwards?
      • How do I pass int64_t and uint64_t values from js into wasm functions?
      • Can I use multiple Emscripten-compiled programs on one Web page?
      • Can I build JavaScript that only runs on the Web?
      • Why the weird name for the project?
  • Compiling and Running Projects
    • Building Projects
      • Integrating with a build system
      • Emscripten linker output files
      • Building projects with optimizations
      • Building projects with debug information
      • Using libraries
      • Emscripten Ports
        • Adding more ports
      • Build system issues
        • Build system self-execution
        • Faux Dynamic Linking
        • Configure may run checks that appear to fail
        • Archive (.a) files
      • Manually using emcc
      • Detecting Emscripten in Preprocessor
      • Using a compiler wrapper
      • pkg-config
      • Examples / test code
      • Troubleshooting
    • Building to WebAssembly
      • Setup
        • Backends
      • Trapping
      • Compiler output
      • Testing native WebAssembly in browsers
      • .wasm files and compilation
      • Web server setup
    • Dynamic Linking
      • Background
      • Overview of Dynamic Linking
      • Practical Details
        • Load-time Dynamic Linking
        • Runtime Dynamic Linking with dlopen()
      • Code Size
      • System Libraries
      • Miscellaneous Notes
        • Dynamic Checks
        • Limitations
        • Pthreads support
    • Running HTML files with emrun
      • Features
      • Quick how-to
      • Choosing the browser to run
      • Security implications
      • Controlling web server operation
      • Controlling log output
      • Cleaning up after the run
      • Running web pages in Firefox
      • Running web pages on an Android device
    • Building projects on Travis CI
      • A sample .travis.yml
    • Deploying Emscripten Compiled Pages
      • Build Files and Custom Shell
      • Optimizing Download Sizes
      • Optimizing Page Startup Times
      • Providing a Quick Second Time Load
      • Reserving Memory for Compiled Code
      • Robust Error Handling
      • Prepare for The Web Environment
    • Building and Deploying on GitLab
      • A sample .gitlab-ci.yml
  • Porting
    • Code Portability and Limitations
      • Portability Guidelines
        • Current Web limitations
        • Code that cannot be compiled
        • Code that compiles but might run slowly
        • Other issues
      • API Limitations
        • Networking
        • File Systems
        • Application Main Loop
        • Other APIs
      • Function Pointer Issues
        • Debugging function pointer issues
        • Working around function pointer issues
      • Specific Browser Limitations
    • Emscripten Runtime Environment
      • Input/output
      • File Systems
      • Browser main loop
        • Implementing an asynchronous main loop in C/C++
        • Using Asyncify to yield to the browser
      • Execution lifecycle
      • Emscripten memory representation
    • Connecting C++ and JavaScript
      • Interacting with code
        • Calling compiled C functions from JavaScript using ccall/cwrap
        • Interacting with an API written in C/C++ from NodeJS
        • Call compiled C/C++ code “directly” from JavaScript
        • Calling JavaScript from C/C++
        • Implement a C API in JavaScript
        • Calling JavaScript functions as function pointers from C
        • Access memory from JavaScript
        • Affect execution behaviour
        • Environment variables
        • Binding C++ and JavaScript — WebIDL Binder and Embind
        • Binding C/C++ and JavaScript - Node-API
      • Embind
        • A quick example
        • Binding libraries
        • Classes
        • Memory management
        • Value types
        • Advanced class concepts
        • Overloaded functions
        • Enums
        • Constants
        • Memory views
        • Using val to transliterate JavaScript to C++
        • Built-in type conversions
        • Performance
      • WebIDL Binder
        • A quick example
        • Modular output
        • Using C++ classes in JavaScript
        • Attributes
        • Pointers, References, Value types (Ref and Value)
        • Const
        • Un-deletable classes (NoDelete)
        • Defining inner classes and classes inside namespaces (Prefix)
        • Operators
        • enums
        • Sub-classing C++ base classes in JavaScript (JSImplementation)
        • Pointers and comparisons
        • NULL
        • void*
        • WebIDL types
        • Test and example code
    • Files and File Systems
      • File System Overview
        • Emscripten file system runtime environment
        • Emscripten file system architecture
      • Packaging Files
        • Packaging using emcc
        • Packaging using the file packager tool
        • Changing the data file location
        • Modifying file locations in the virtual file system
        • Valid Character Set
        • Monitoring file usage
        • Preloading files
        • Test code
      • Synchronous Virtual XHR Backed File System Usage
        • Test code
        • Instructions
    • Multimedia and Graphics
      • EGL Support in Emscripten
        • What EGL is not?
        • How to create a WebGL context using EGL?
        • Implementation status and notes
      • OpenGL support in Emscripten
        • WebGL-friendly subset of OpenGL ES 2.0/3.0
        • OpenGL ES 2.0/3.0 emulation
        • Emulation of older Desktop OpenGL API features
        • OpenGL ES extensions
        • Test code/examples
        • Bug Reports
    • Audio
      • Supported OpenAL extensions
      • Guidelines for Audio on Emscripten
      • Emscripten-specific capture behavior
      • Useful implementation details of OpenAL capture
      • Improving and extending the implementation
    • Debugging
      • Debug information
      • Debug mode (EMCC_DEBUG)
      • Compiler settings
      • Sanitizers
      • emcc verbose output
      • Manual print debugging
      • Handling C++ exceptions from JavaScript
      • Emscripten-specific issues
        • Memory Alignment Issues
        • Function Pointer Issues
        • Infinite loops
      • Profiling
        • Speed
        • Memory
      • AutoDebugger
        • AutoDebugger Regression Workflow
      • Useful Links
      • Need help?
    • Pthreads support
      • Compiling with pthreads enabled
      • Additional flags
      • Proxying
      • Blocking on the main browser thread
      • Special considerations
      • Running code and tests
    • Networking
      • Emscripten WebSockets API
      • Emulated POSIX TCP Sockets over WebSockets
      • Full POSIX Sockets over WebSocket Proxy Server
      • XmlHttpRequests and Fetch API
      • WebRTC and UDP
    • Porting SIMD code targeting WebAssembly
    • Limitations and behavioral differences
    • Optimization considerations
    • Compiling SIMD code targeting x86 SSE instruction set
    • Compiling SIMD code targeting ARM NEON instruction set
    • C++ Exceptions Support
      • JavaScript-based Exception Support
      • WebAssembly Exception Handling-based Support
      • Debugging Exceptions
        • Stack Traces
        • Exception Messages
      • Using Exceptions and setjmp-longjmp Together
    • C setjmp-longjmp Support
      • JavaScript-based setjmp-longjmp Support
      • WebAssembly Exception Handling-based setjmp-longjmp Support
      • Using Exceptions and setjmp-longjmp Together
    • Asyncify
      • Sleeping / yielding to the event loop
      • Making async Web APIs behave as if they were synchronous
      • Ways to use async APIs in older engines
      • More on ASYNCIFY_IMPORTS
      • Asyncify with Dynamic Linking
      • Usage with Embind
      • Usage with ccall
      • Optimizing
      • Potential problems
        • Stack overflows
        • Reentrancy
        • Starting to rewind with compiled code on the stack
      • Migrating from older APIs
    • Building Projects
      • Integrating with a build system
      • Emscripten linker output files
      • Building projects with optimizations
      • Building projects with debug information
      • Using libraries
      • Emscripten Ports
        • Adding more ports
      • Build system issues
        • Build system self-execution
        • Faux Dynamic Linking
        • Configure may run checks that appear to fail
        • Archive (.a) files
      • Manually using emcc
      • Detecting Emscripten in Preprocessor
      • Using a compiler wrapper
      • pkg-config
      • Examples / test code
      • Troubleshooting
  • API Reference
    • emscripten.h
      • Inline assembly/JavaScript
        • Defines
      • Calling JavaScript From C/C++
        • Function pointer types for callbacks
        • Functions
      • Browser Execution Environment
        • Functions
      • Asynchronous File System API
        • Typedefs
        • Functions
      • Asynchronous IndexedDB API
      • Compiling
      • Worker API
        • Typedefs
        • Functions
      • Logging utilities
        • Defines
        • Functions
      • Socket event registration
        • Callback functions
        • Functions
      • Unaligned types
        • Typedefs
      • Pseudo-synchronous functions
        • Sleeping
        • Network
        • IndexedDB
      • Upstream Asyncify functions
        • Typedefs
        • Functions
      • ABI functions
    • html5.h
      • How to use this API
        • Registration functions
        • Callback functions
        • Functions affected by web security
        • Test/Example code
      • General types
      • Function result values
      • Keys
        • Defines
        • Struct
        • Callback functions
        • Functions
      • Mouse
        • Defines
        • Struct
        • Callback functions
        • Functions
      • Wheel
        • Defines
        • Struct
        • Callback functions
        • Functions
      • UI
        • Defines
        • Struct
        • Callback functions
        • Functions
      • Focus
        • Defines
        • Struct
        • Callback functions
        • Functions
      • Device orientation
        • Defines
        • Struct
        • Callback functions
        • Functions
      • Device motion
        • Defines
        • Struct
        • Callback functions
        • Functions
      • Orientation
        • Defines
        • Struct
        • Callback functions
        • Functions
      • Fullscreen
        • Defines
        • Struct
        • Callback functions
        • Functions
      • Pointerlock
        • Defines
        • Struct
        • Callback functions
        • Functions
      • Visibility
        • Defines
        • Struct
        • Callback functions
        • Functions
      • Touch
        • Defines
        • Struct
        • Callback functions
        • Functions
      • Gamepad
        • Defines
        • Struct
        • Callback functions
        • Functions
      • Battery
        • Defines
        • Struct
        • Callback functions
        • Functions
      • Vibration
        • Functions
      • Page unload
        • Defines
        • Callback functions
        • Functions
      • WebGL context
        • Defines
        • Struct
        • Callback functions
        • Functions
      • CSS
        • Functions
      • Animation and Timing
        • Functions
      • Console
        • Functions
      • Throw
        • Functions
    • preamble.js
      • Calling compiled C functions from JavaScript
      • Accessing memory
      • Conversion functions — strings, pointers and arrays
      • Run dependencies
      • Stack trace
      • Type accessors for the memory model
    • File System API
      • New File System: WasmFS
      • Including File System Support
      • Persistent data
      • File systems
        • MEMFS
        • NODEFS
        • NODERAWFS
        • IDBFS
        • WORKERFS
        • PROXYFS
      • Devices
      • Setting up standard I/O devices
      • File system API
      • File types
      • Paths
    • Fetch API
      • Introduction
      • Persisting data
        • Persisting data bytes from memory
        • Deleting a file from IndexedDB
      • Synchronous Fetches
      • Waitable Fetches
      • Tracking Progress
      • Managing Large Files
        • Downloading directly to IndexedDB
        • Streaming Downloads
        • Byte Range Downloads
      • TODO To Document
    • Module object
      • Creating the Module object
      • Compilation settings
      • Affecting execution
      • Other methods
    • val.h
    • bind.h (under-construction)
      • How to use this API
        • Defines
      • Policies
      • select_overload and select_const
      • Functions
      • Value tuples
      • Value structs
      • Smart pointers
      • Classes
      • Vectors
      • Maps
      • Enums
      • Constants
    • trace.h
      • Usage
        • Compiler Interaction
        • Initialization and Teardown
        • Contexts
        • Frames
        • Annotating Allocations
        • Overall Memory Usage
        • Logging Messages
        • Tasks
        • Reporting Errors
      • Running the Server
      • Design Notes
        • Client / Server Design
        • Data Batching
        • Do Not Perturb The Heap
      • Functions
    • fiber.h
      • API Reference
        • Types
        • Functions
    • proxying.h
      • API Reference
        • Types
        • Functions
        • C++ API
    • Wasm Workers API
      • Quick Example
      • Introduction
      • Pthreads vs Wasm Workers: Which One to Use?
        • Pthreads can proxy JS functions
        • Pthreads have cancellation points
        • Pthreads may start up synchronously - Wasm Workers always start asynchronously
        • Pthread topology is flat - Wasm Workers are hierarchical
        • Pthreads can use the Wasm Worker synchronization API, but not vice versa
        • Pthreads have a “thread main” function and atexit handlers
        • Pthreads have a per-thread incoming proxy message queue, Wasm Workers do not
        • Pthreads synchronize wallclock times
        • Input events API backproxies only to pthreads
        • Pthread vs emscripten_lock implementation differences
        • Memory requirements
        • Generated code size
        • API Differences
      • Limitations
      • Example Code
    • Wasm Audio Worklets API
      • Development Overview
      • Programming Example
      • Synchronizing audio thread with the main thread
      • More Examples
    • Advanced APIs
      • settings.js
      • preamble.js
      • Advanced File System API
  • Tools Reference
    • Emscripten SDK (emsdk)
      • Command line syntax
        • Arguments
        • Tools and SDK targets
      • SDK concepts
      • Emscripten Compiler Configuration File (.emscripten)
      • “How to” guides
        • How do I just get the latest SDK?
        • How do I use emsdk?
        • How do I check which versions of the SDK and tools are installed?
        • How do I install a tool/SDK version?
        • How do I remove a tool or an SDK?
        • How do I check for updates to the Emscripten SDK?
        • How do I change the currently active SDK version?
        • How do I install and activate old Emscripten SDKs and tools?
        • How do I track the latest Emscripten development with the SDK?
        • How do I use my own Emscripten GitHub fork with the SDK?
    • Emscripten Compiler Frontend (emcc)
      • Command line syntax
        • Arguments
      • Environment variables
    • Emscripten Windows Command Prompt (emcmdprompt.bat)
      • Command line syntax
  • Optimizing Code
    • How to optimize code
    • How Emscripten optimizes
    • Link Times
    • Advanced compiler settings
    • WebAssembly
    • Code size
      • Trading off code size and performance
      • Miscellaneous code size tips
    • LTO
    • EVAL_CTORS
    • Very large codebases
      • Running by itself
      • Module Splitting
    • Other optimization issues
      • C++ exceptions
      • C++ RTTI
      • Memory Growth
      • Viewing code optimization passes
    • Unsafe optimizations
    • Profiling
    • Troubleshooting poor performance
  • Optimizing WebGL
    • Which GL Mode To Target?
    • How To Profile WebGL
    • Avoid Redundant Calls
    • Techniques To Minimize API Calls
    • Avoid GPU-CPU Sync Points
    • GPU Driver Friendly Memory Access Behavior
    • When The GPU Is The Bottleneck
    • Optimizing Load Times and Other Best Practices
    • Migrating To WebGL 2
  • Debugging with Sanitizers
    • Undefined Behaviour Sanitizer
      • Catching Null Dereference
      • Minimal Runtime
    • Address Sanitizer
      • Examples
        • Buffer Overflow
        • Use After Free
        • Memory Leaks
        • Use After Return
      • Configuration
        • Disabling malloc/free Stack Traces
      • Comparison to SAFE_HEAP
  • Building Emscripten from Source
    • Building LLVM
    • Building Binaryen
      • Emscripten Toolchain Requirements
        • What you’ll need
        • Test which tools are installed
      • Configuring Emscripten Settings when Manually Building from Source
        • Creating the compiler configuration file
        • Locating the compiler configuration file (.emscripten)
        • Compiler configuration file-format
        • Editing the compiler configuration file
      • Verifying the Emscripten Development Environment
        • Testing the environment
        • Troubleshooting
  • Contributing to Emscripten
    • Contributing
      • Getting started
      • Next steps
    • Developer’s Guide
      • Setting up
      • Repositories and branches of interest
      • Submitting patches
      • Code reviews
      • Compiler overview
      • Emscripten Test Suite
      • Bisecting
      • See also
    • AUTHORS
  • Profiling the Toolchain
    • Quick Example
    • Details
      • Profiling Tool Commands
    • Instrumenting Python Scripts
      • Python Profiling Blocks
  • About this site
    • Searching the site
    • Reporting bugs
    • Contributing to the site
    • Building the site
      • Installing Sphinx
      • Site builds
      • SDK Builds
      • Build version
    • Writing and updating articles
      • Style guide
      • How to link to a document or heading
      • Recommended section/heading markup
      • Working in markdown
    • Read the docs theme
    • Site license
Index
 
Logo
Fork me on GitHub
  • DocsDocumentation
  • SDKDownloads
  • HelpCommunity
  • GitHub
Home
» Porting

Porting¶

The topics in this section cover the main integration points that you need to consider when porting C/C++ code to Emscripten, along with general coding and debugging guidelines.

  • Code Portability and Limitations
  • Emscripten Runtime Environment
  • Connecting C++ and JavaScript
  • Files and File Systems
  • Multimedia and Graphics
  • Audio
  • Debugging
  • Pthreads support
  • Networking
  • Porting SIMD code targeting WebAssembly
  • Limitations and behavioral differences
  • Optimization considerations
  • Compiling SIMD code targeting x86 SSE instruction set
  • Compiling SIMD code targeting ARM NEON instruction set
  • C++ Exceptions Support
  • C setjmp-longjmp Support
  • Asyncify
  • Building Projects
Next Previous
Report BugReport Bug LicensingLicensing ContributingContributing Mailing listMailing list WikiWiki Release notesRelease notes BlogsBlogs HelpContact
  • About site
  • Page bug

© Copyright 2015, Emscripten Contributors.