Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Environment:Alibaba MNN CPU Build Environment

From Leeroopedia


Field Value
Environment Name CPU_Build_Environment
Knowledge Sources MNN repository: CMakeLists.txt, docs/compile/cmake.md, docs/compile/engine.md
Domain Infrastructure
Description Base CPU compilation environment for building MNN core library and tools
Last Updated 2026-02-10

Overview

Base CPU compilation environment for building the MNN core library and tools. This environment defines the minimum toolchain requirements for a successful source build of MNN on desktop platforms. It requires CMake 3.6+, a C++11-compatible compiler (GCC 4.9+ or Clang), and C99 support. All GPU, mobile, and accelerator backends have their own environment pages; this page covers only the CPU-only base build.

System Requirements

Component Requirement Notes
Operating System Linux, macOS, Windows (MSVC or MinGW) All three platforms are supported as first-class build targets
CMake >= 3.6 (3.10 recommended, 3.13 for Windows) cmake_minimum_required(VERSION 3.6) declared at CMakeLists.txt:L1
C++ Compiler GCC >= 4.9, Clang, or MSVC >= 2017 Must support C++11 at minimum
C++ Standard C++11 (default), C++17 optional set(CMAKE_CXX_STANDARD 11) at CMakeLists.txt:L24; C++17 enabled when CUDA transformer fuse is active
C Standard C99 set(CMAKE_C_STANDARD 99) at CMakeLists.txt:L22
Disk Space ~500MB for build artifacts Varies with enabled options; converter and protobuf add significant output

Dependencies

Required (System)

  • cmake >= 3.6 -- Build system generator
  • gcc >= 4.9 or clang -- C/C++ compiler with C99 and C++11 support
  • make or ninja -- Build executor (Ninja recommended on Windows)

Optional

  • protobuf 3.0+ -- Required for TensorFlow and Caffe converter backends. Can use MNN's bundled copy by setting -DMNN_BUILD_PROTOBUFFER=ON (the default).
  • flatbuffers -- Schema compiler for MNN model format. Bundled in 3rd_party/flatbuffers; no system install needed.

Credentials

None required for base build. The MNN repository is publicly available and all dependencies are either bundled or available through standard package managers.

Quick Install

Linux / macOS

# Linux/macOS
mkdir build && cd build
cmake .. -DMNN_BUILD_CONVERTER=ON -DMNN_BUILD_QUANTOOLS=ON
make -j8

Windows (MSVC)

# Windows (MSVC)
mkdir build && cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..
ninja

Code Evidence from CMakeLists.txt

The following excerpts from the root CMakeLists.txt document the environment constraints:

# Line 1: Minimum CMake version
cmake_minimum_required(VERSION 3.6)

# Line 20: Project declaration with C, C++, and ASM languages
project(MNN VERSION ${MNN_VERSION} LANGUAGES C CXX ASM)

# Lines 22-24: Language standard requirements
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
# or, when MNN_CUDA and MNN_CUDA_QUANT are both ON:
set(CMAKE_CXX_STANDARD 17)

# Lines 31-36: Windows-specific MSVC checks
if(MSVC)
  # MSVC-specific configuration and runtime flags
  # MNN_SEP_BUILD forced OFF on Windows
endif()

# Lines 196-205: Protobuf build configuration
option(MNN_BUILD_PROTOBUFFER "Build with protobuffer in MNN" ON)
# When ON, builds protobuf from 3rd_party/protobuf/cmake

Common Errors

Error Message Cause Solution
Could NOT find Protobuf System protobuf not installed and built-in not enabled Use -DMNN_BUILD_PROTOBUFFER=ON to build protobuf from MNN's bundled sources
Unrecognized syntax "proto3" System protobuf version is too old (pre-3.0) Upgrade to protobuf 3.0+ or use the built-in protobuf with -DMNN_BUILD_PROTOBUFFER=ON
CMake Error: Could not find CMAKE_ROOT CMake is not installed properly or not on PATH Install CMake via sudo apt install cmake extra-cmake-modules or download from cmake.org

Compatibility Notes

  • Windows: MNN_SEP_BUILD is forced to OFF on Windows regardless of user setting, because the separated backend build model is not supported on that platform.
  • macOS + Framework: MNN_SEP_BUILD and MNN_AAPL_FMWK cannot coexist. Enabling Apple Framework output requires MNN_SEP_BUILD=OFF.
  • Static library linking: When linking against a static MNN build, whole-archive flags are required to prevent the linker from stripping unreferenced backend registration symbols:
    • GCC / Linux: -Wl,--whole-archive libMNN.a -Wl,--no-whole-archive
    • macOS: -Wl,-force_load,libMNN.a
    • MSVC: /WHOLEARCHIVE:MNN.lib

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment