Skip to content

Instantly share code, notes, and snippets.

@awni
Last active October 23, 2024 22:00
Show Gist options
  • Save awni/112ff52290e6b7602183d1e6a809166f to your computer and use it in GitHub Desktop.
Save awni/112ff52290e6b7602183d1e6a809166f to your computer and use it in GitHub Desktop.
Minimal MLX CMake
cmake_minimum_required(VERSION 3.27)
project(_ext LANGUAGES CXX)
# ----------------------------- Setup -----------------------------
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
option(BUILD_SHARED_LIBS "Build as a shared library" ON)
# ----------------------------- Dependencies -----------------------------
find_package(MLX CONFIG REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main PUBLIC mlx)
#include <iostream>
#include <mlx/mlx.h>
using namespace mlx::core;
int main () {
auto a = array({1,2,3});
std::cout << a << std::endl;
return 0;
}
@awni
Copy link
Author

awni commented Oct 17, 2024

To build you should have MLX installed. If you installed it with Python you can do something like this:

mkdir build
cd build
MLX_DIR=`python -c "import mlx.core as mx; import os; print(os.path.dirname(mx.__file__))"` cmake ..
make -j4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment