How to compile llama.cpp
Quick answer
To compile
llama.cpp, clone the repository, install dependencies like cmake and a C++ compiler, then run cmake . followed by make in the project directory. This builds the executable for use with ollama or local inference.PREREQUISITES
C++17 compatible compiler (gcc, clang, or MSVC)CMake 3.15+ installedGit installedMake (Linux/macOS) or build tools for WindowsBasic terminal/command line knowledge
Setup
First, ensure you have git, cmake, and a C++17 compiler installed. On macOS, install Xcode Command Line Tools and cmake via Homebrew. On Linux, use your package manager to install build-essential and cmake. On Windows, install Visual Studio with C++ workload and CMake.
git --version
cmake --version
clang --version # or gcc --version output
git version 2.40.1 cmake version 3.26.4 Apple clang version 14.0.0 (clang-1400.0.29.202)
Step by step
Clone the llama.cpp repository and build it using cmake and make:
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
cmake .
make output
Scanning dependencies of target llama [ 50%] Building CXX object CMakeFiles/llama.dir/llama.cpp.o [100%] Linking CXX executable llama [100%] Built target llama
Common variations
For Windows, use Visual Studio to open the generated llama.sln file and build the project. To build with specific options, pass flags to cmake, e.g., cmake -DLLAMA_CUBLAS=ON . for CUDA support. You can also build with ninja if preferred.
cmake -G Ninja .
ninja output
[100%] Built target llama
Troubleshooting
- If
cmakefails, verify your compiler supports C++17 and your environment variables are set correctly. - On Windows, ensure the Visual Studio Developer Command Prompt is used.
- If
makeis not found, install it or use an alternative build system like Ninja.
Key Takeaways
- Use CMake and a C++17 compiler to build llama.cpp from source.
- On Windows, prefer Visual Studio or Ninja for building.
- Check environment and dependencies if build errors occur.