Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/codewithmirza/sample3
compiling C++ to wasm using Emscripten
https://github.com/codewithmirza/sample3
emscripten webassembly windows
Last synced: about 2 months ago
JSON representation
compiling C++ to wasm using Emscripten
- Host: GitHub
- URL: https://github.com/codewithmirza/sample3
- Owner: codewithmirza
- License: apache-2.0
- Created: 2024-03-26T13:44:24.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-03-26T14:37:44.000Z (10 months ago)
- Last Synced: 2024-08-21T06:55:25.594Z (5 months ago)
- Topics: emscripten, webassembly, windows
- Language: JavaScript
- Homepage:
- Size: 131 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Building C++ Projects with Emscripten on Windows
This guide will walk you through the process of setting up and building a C++ project with Emscripten on a Windows system. We'll use CMake for project configuration and Emscripten to compile our C++ code into WebAssembly format for web deployment.
## Prerequisites
Before getting started, make sure you have the following installed on your system:
- Emscripten: You can download and install Emscripten from the [official website](https://emscripten.org/docs/getting_started/downloads.html).
- CMake: You can download and install CMake from the [official website](https://cmake.org/download/).## Step-by-Step Guide
### 1. Set up Emscripten
Ensure Emscripten is properly installed on your Windows system. You can follow the instructions provided on the [Emscripten Installation Guide](https://emscripten.org/docs/getting_started/downloads.html).
### 2. Prepare Your Project
Create a new directory for your project and add the necessary files:
- `CMakeLists.txt`: Main CMake configuration file.
- Your C++ source files (`calc.cpp`, `calc.hpp`, `test.cpp`, etc.).### 3. Configure CMakeLists.txt
Inside your project directory, create a `CMakeLists.txt` file with the following contents:
```cmake
cmake_minimum_required(VERSION 3.0)
project(my_project)# Add your source files here
set(SOURCES
calc.cpp
calc.hpp
test.cpp
)# Set the output directory for the build
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)# Create the executable
add_executable(my_project ${SOURCES})# Set C++ standard to C++17
target_compile_features(my_project PUBLIC cxx_std_17)
```### 4. Build Your Project with Emscripten
- Open a command prompt or terminal window and navigate to your project directory.
- Activate the latest installed version of Emscripten using the command:### 4. Build Your Project with Emscripten
- Open a command prompt or terminal window and navigate to your project directory.
- Activate the latest installed version of Emscripten using the command:
`emsdk activate latest`- Set up the environment variables for using Emscripten:
`emsdk_env.bat`- Generate the build files using CMake:
```
mkdir build
cd build
emcmake cmake ..
```- Build your project:
`emmake make`This will compile your C++ code into WebAssembly format using Emscripten. The resulting ``sample3.wasm`` can be found in `build/bin`.
### Additional Notes
- You can customize the project structure and CMake configuration to suit your specific requirements.
- Emscripten provides various options and optimizations for building WebAssembly applications. Refer to the [official documentation](https://emscripten.org/docs/) for more details.Feel free to reach out if you encounter any issues or have any questions!