Setting Up MeshLib for C++ Development
This guide provides detailed instructions for setting up MeshLib for C++ development across Windows, Linux, and macOS. It covers all prerequisites as well as specific setup steps for each platform.
Windows
Prerequisites
- Git
- Install Git to manage repositories and submodules, which is also required to install
vcpkg
.
- Visual Studio 2019 or 2022
- CUDA Toolkit
- For Visual Studio 2019: Install CUDA v11.4
- For Visual Studio 2022: Install CUDA v12.0
Choose the appropriate version based on your Visual Studio installation.
- vcpkg
- To install
vcpkg
, follow these steps:
- Open a command prompt (CMD) or PowerShell window.
- Navigate to a directory where you want to install
vcpkg
: cd C:\path\to\your\desired\directory
- Clone the
vcpkg
repository: git clone https://github.com/microsoft/vcpkg.git
- Navigate to the
vcpkg
directory: cd vcpkg
git checkout 2024.10.21
- Run the bootstrap script to build the
vcpkg
executable:
- Integrate **
vcpkg
**with Visual Studio (requires Administrator access):
Learn more about vcpkg
Installing the local build
- Note
- The following steps will require approximately 40 GB of disk space.
- Clone the MeshLib Repository:
git clone --recurse-submodules https://github.com/MeshInspector/MeshLib.git
- (Optional) Speed Up with AWS CLI
- Optionally, install AWS CLI v2 to speed up the process before using the MeshLib Installation Script. Restart your terminal after installation.
- Install MeshLib Third-Party Dependencies
- Execute the following commands to run the MeshLib third-party installation script:
cd vcpkg
..\MeshLib\thirdparty\install.bat
- This script automates the installation of necessary third-party dependencies.
- Build and Run:
- Open
MeshLib/source/MeshLib.sln
in Visual Studio.
- Build the solution and run the application.
Installing the release build
- Download and Extract the Built Version
- Visit the MeshLib GitHub Releases.
- Download the latest Windows built version archive (E.g. MeshLibDist_v3.0.0.40.zip).
- Extract it to a directory, e.g.,
C:\meshlib-built\
.
Directory Structure After Extraction install/
├── include/ # Header files
├── lib/ # Static and shared libraries
├── bin/ # Executables
example_plugin/ # example solution for creating plugins
- Configure and integrate with Visual Studio
- C/C++ → General → Additional Include Directories:
Add: C:\meshlib-built\install\include
- Linker → General → Additional Library Directories:
Add: C:\meshlib-built\install\app\$(Configuration)
- Linker → Input → Additional Dependencies:
Add: C:\meshlib-built\install\lib\$(Configuration)\*.lib
- Debug Configuration: C/C++ → Preprocessor → Preprocessor Definitions:
Add: _ITERATOR_DEBUG_LEVEL=0
- Copy DLLs:
Copy all .dll
files from: C:\meshlib-built\install\app\$(Configuration)
to your project’s output directory: $(TargetDir)
xcopy C:\meshlib-built\install\app\$(Configuration)\*.dll $(TargetDir)
Linux (Ubuntu/Fedora)
Prerequisites
- Git
- CMake
- Ensure CMake is installed for managing the build process.
- CUDA Toolkit
- Install CUDA v12.0 from the official website. Follow the Linux installation instructions provided on the CUDA page.
Installing the local build
- Clone the MeshLib Repository:
git clone --recurse-submodules https://github.com/MeshInspector/MeshLib.git
cd MeshLib
- Install/Build Dependencies and Compile:
./scripts/build_thirdparty.sh # Do not select emscripten in the corresponding question
./scripts/build_source.sh # Do not select emscripten in the corresponding question
- Create and Install Package:
This step will create distribution package and install it to the system
For Ubuntu: ./scripts/distribution.sh
sudo apt install ./distr/meshlib-dev.deb
For Fedora**: ./scripts/distribution_rpm.sh
sudo rpm -i ./distr/meshlib-dev.rpm
- Open MeshViewer
To verify that everything is fine you can run MeshViewer application:
- if you previously have installed
meshlib
to your system:
- or run locally built binary
MR_LOCAL_RESOURCES=1 ./build/Release/bin/MeshViewer
- Integrate Using CMake
Examples of integration with CMake can be found in the examples directory on GitHub.
Installing the release build
- Download and Extract the Built Version
- Install Linux Build
- For Ubuntu:
sudo apt install ./meshlib-build-version-example.deb
- For Fedora:
sudo rpm -i ./meshlib-build-version-example.rpm
- Open MeshViewer
To verify that everything is fine you can run MeshViewer application:
- Integrate Using CMake
Examples of integration with CMake can be found in the examples directory on GitHub.
macOS
Prerequisites
- Install Homebrew
- Run the following command in your terminal to install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install Homebrew
- Update Homebrew
- Make sure Homebrew is up to date:
- Install Git Using Homebrew
- Once Homebrew is installed and added to your PATH, you can proceed to install Git:
- Learn more about Git
Installing the local build
- Clone the MeshLib Repository:
git clone --recurse-submodules https://github.com/MeshInspector/MeshLib.git
cd MeshLib
- Install/Build Dependencies and Compile:
./scripts/build_thirdparty.sh
./scripts/build_source.sh
- Open MeshViewer
MR_LOCAL_RESOURCES=1 ./build/Release/bin/MeshViewer
The new window with a viewer must appear.
- Integrate Using CMake
Examples of integration with CMake can be found in the examples directory on GitHub.
Installing the release build
- Download the Built Version
Visit the MeshLib GitHub Releases and download the latest macOS built version.
- Install Using macOS Installer
- Double-click the
.pkg
file included in the downloaded package, and follow the instructions to complete the installation.
- Install Dependencies via Homebrew
Open Terminal and run the following command: xargs brew install < /opt/meshlib/requirements/macos.txt
- Integrate Using CMake
Examples of integration with CMake can be found in the examples directory on GitHub.
Building WebAssembly with MeshLib Using Emscripten
This guide will help you build WebAssembly (WASM) using MeshLib and Emscripten. Please follow the instructions step by step.
Install Emscripten
Emscripten is required to compile C++ code into WebAssembly. You can install Emscripten by following the steps below. For more details, refer to the Emscripten official page.
- Clone the Emscripten SDK Repository
Run the following command on all platforms: git clone https://github.com/emscripten-core/emsdk.git
- Navigate to the Emscripten SDK Directory
- Update the SDK (Optional)
This step ensures you have the latest updates:
- Install a Specific Version of Emscripten
- Activate the Installed Version
- Set Up Environment Variables
- Note
- For Windows Users:
Make sure you are using Git Bash, WSL, or another Unix-like environment if you want to follow the exact same steps as on Linux/macOS.
Building MeshLib
Now that Emscripten is set up, you can proceed to build MeshLib for WebAssembly.
- Navigate to the MeshLib directory:
- Run the script to build third-party dependencies. When prompted, select Emscripten as the build target:
- Choose
y
for multithreaded, s
for single-threaded, or n
for a standard Linux build. ./scripts/build_thirdparty.sh
- Build the MeshLib source code. Make sure to select the same Emscripten option you used in the
build_thirdparty.sh
script: ./scripts/build_source.sh
- Note
- For Windows Users:
You may encounter compatibility issues if building directly on Windows. Consider using WSL (Windows Subsystem for Linux) to follow Linux-like instructions.
Running the WebAssembly Build
After building MeshLib for WebAssembly, follow these steps to run it:
- Setting Up a Local HTTP Server
- Navigate to the build directory:
- Start a local server:
Configuring COEP and COOP for Multithreading
If using multithreading, set these headers:
- Cross-Origin Embedder Policy (COEP):
require-corp
- Cross-Origin Opener Policy (COOP):
same-origin
For Python servers, you can use this custom script (server.py
):
from http import server
class MyHTTPRequestHandler(server.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
server.SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
if __name__ == '__main__':
server.test(HandlerClass=MyHTTPRequestHandler)
- Access and Test
- Open your browser and go to:
http://127.0.0.1:8000
- Ensure headers are set correctly for multithreading. Check the browser console for errors if needed.