Skip to main content
MLPP is a header-only library designed for seamless integration into CMake-based C++ projects. This guide covers installation, configuration, and dependency management.

Requirements

MLPP requires C++20 or later and CMake 3.20+
Core dependencies:
  • C++20 compatible compiler (GCC 10+, Clang 12+, MSVC 2019+)
  • CMake 3.20 or later
  • Eigen3 3.4+ (recommended but optional)
Optional dependencies:
  • Python 3 + NumPy (for plotting via MLPP_WITH_PYPLOT)
  • OpenCV (for image processing via MLPP_WITH_OPENCV)

Installation

1

Clone the repository

git clone https://github.com/HanielUlises/Machine-Learning-Cpp.git
cd Machine-Learning-Cpp
2

Install with CMake

Standard installation to your system:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
sudo cmake --install build
This installs headers to /usr/local/include/mlpp and CMake config files to /usr/local/lib/cmake/mlpp.
3

Integrate into your project

In your project’s CMakeLists.txt, add:
find_package(mlpp 0.3 REQUIRED)
target_link_libraries(your_target PRIVATE mlpp::mlpp)

CMake configuration options

MLPP provides several build options to customize functionality:
OptionDefaultDescription
MLPP_BUILD_TESTSONBuild unit tests
MLPP_BUILD_EXAMPLESONBuild example programs
MLPP_WITH_PYPLOTONEnable matplotlib plotting (requires Python+NumPy)
MLPP_WITH_OPENCVONEnable OpenCV support for image data
MLPP_USE_EIGENONUse Eigen3 for linear algebra (highly recommended)

Example: minimal installation

To install only the core library without tests or optional dependencies:
cmake -B build \
  -DCMAKE_BUILD_TYPE=Release \
  -DMLPP_BUILD_TESTS=OFF \
  -DMLPP_BUILD_EXAMPLES=OFF \
  -DMLPP_WITH_PYPLOT=OFF \
  -DMLPP_WITH_OPENCV=OFF
cmake --build build
sudo cmake --install build

Using MLPP as a subdirectory

For tighter integration, include MLPP directly in your project:
1

Add as Git submodule

git submodule add https://github.com/HanielUlises/Machine-Learning-Cpp.git external/mlpp
2

Update your CMakeLists.txt

# Add MLPP subdirectory
add_subdirectory(external/mlpp)

# Link against your target
add_executable(my_app main.cpp)
target_link_libraries(my_app PRIVATE mlpp::mlpp)
This approach gives you full control over MLPP’s build options without system-wide installation.

Dependency management

MLPP performs best with Eigen3 for optimized linear algebra:
sudo apt-get install libeigen3-dev
When Eigen3 is detected, MLPP automatically defines MLPP_HAS_EIGEN and links against Eigen3::Eigen.
If Eigen3 is not found, the library falls back to standard library implementations with reduced performance.

Python + NumPy (for plotting)

To enable matplotlib-based plotting:
pip install numpy matplotlib
CMake will automatically detect Python and NumPy when MLPP_WITH_PYPLOT=ON:
find_package(Python3 REQUIRED COMPONENTS Interpreter Development NumPy)
target_link_libraries(mlpp INTERFACE Python3::Python Python3::NumPy)
target_compile_definitions(mlpp INTERFACE MLPP_WITH_PYPLOT)

OpenCV (for image processing)

Install OpenCV development files:
sudo apt-get install libopencv-dev
MLPP links against OpenCV core modules when detected:
find_package(OpenCV QUIET COMPONENTS core imgproc highgui)
if(OpenCV_FOUND)
    target_link_libraries(mlpp INTERFACE opencv_core opencv_imgproc opencv_highgui)
    target_compile_definitions(mlpp INTERFACE MLPP_HAS_OPENCV)
endif()

Verifying installation

Create a minimal test file to verify everything works:
test.cpp
#include <mlpp.h>
#include <iostream>

int main() {
    std::cout << "MLPP loaded successfully!" << std::endl;
    
    #ifdef MLPP_HAS_EIGEN
    std::cout << "Eigen3 support: enabled" << std::endl;
    #endif
    
    #ifdef MLPP_WITH_PYPLOT
    std::cout << "Pyplot support: enabled" << std::endl;
    #endif
    
    return 0;
}
Compile and run:
g++ -std=c++20 test.cpp -o test -I/usr/local/include
./test
Expected output:
MLPP loaded successfully!
Eigen3 support: enabled

Troubleshooting

CMake can’t find mlppEnsure the install prefix is in your CMAKE_PREFIX_PATH:
cmake -B build -DCMAKE_PREFIX_PATH=/usr/local
Missing Eigen3If CMake can’t find Eigen3, specify its location:
cmake -B build -DEigen3_DIR=/path/to/eigen3/share/eigen3/cmake
C++20 not supportedUpdate your compiler or explicitly set the C++ standard:
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Next steps

Quickstart guide

Train your first model with a complete working example

Build docs developers (and LLMs) love