- Prerequisites
- Unix-like OSes
- MinGW/MSYS2 (Windows)
- Microsoft Visual C++
- Emscripten/WebAssembly
- CMake configure options
- Run the tests
- API documentation
- Man page regeneration
You need to have installed a C++ compiler which supports C++11 (or later) and CMake ≥ 3.9.
| macOS | xcode-select --install && brew install cmake |
| Debian/Ubuntu: | sudo apt install g++ cmake |
| Fedora: | sudo dnf install gcc-c++ cmake |
| openSUSE: | sudo zypper install gcc-c++ cmake |
| Arch Linux: | sudo pacman -S gcc cmake |
Open a terminal, cd into the primesieve directory and run:
cmake .
cmake --build . --parallel
sudo cmake --install .
sudo ldconfigOpen a terminal, cd into the primesieve directory and run:
cmake -G "Unix Makefiles" .
cmake --build . --parallelFirst install Visual Studio (includes CMake) on your Windows PC. Then go to the start menu, select Visual Studio and open a x64 Command Prompt. Now cd into the primesieve directory and run the commands below:
# Use 'cmake -G' to find your Visual Studio version
cmake -G "Visual Studio 18 2026" .
cmake --build . --config Release
# Optionally install using Admin shell
cmake --install . --config ReleaseUsing the Emscripten compiler you can compile the primesieve C/C++ library to WebAssembly:
# Install the Emscripten compiler
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source emsdk_env.sh
# Compile primesieve to WebAssembly
git clone https://github.com/kimwalisch/primesieve.git
cd primesieve
emcmake cmake .
emmake make -j4
# Run the primesieve WebAssembly binary
node ./primesieve.js 1e10By default the primesieve binary and the static/shared libprimesieve will be
built. The build options can be modified at the configure step using e.g.
cmake . -DBUILD_TESTS=ON.
option(BUILD_PRIMESIEVE "Build primesieve binary" ON)
option(BUILD_SHARED_LIBS "Build shared libprimesieve" ON)
option(BUILD_STATIC_LIBS "Build static libprimesieve" ON)
option(BUILD_DOC "Build C/C++ API documentation" OFF)
option(BUILD_MANPAGE "Regenerate man page using a2x" OFF)
option(BUILD_EXAMPLES "Build example programs" OFF)
option(BUILD_TESTS "Build test programs" OFF)
option(WITH_MULTIARCH "Enable runtime dispatching to fastest supported CPU instruction set" ON)Open a terminal, cd into the primesieve directory and run:
cmake -DBUILD_TESTS=ON .
cmake --build . --parallel
ctestFor developers hacking on primesieve's source code the test/README.md document contains more information about primesieve testing such as testing in debug mode and testing using GCC/Clang sanitizers.
To build the primesieve C/C++ API documentation in html/PDF format
you need to have installed the doxygen, doxygen-latex and
graphviz (dot) packages.
cmake -DBUILD_DOC=ON .
cmake --build . --target docprimesieve includes an up to date man page at doc/primesieve.1.
That man page has been generated from doc/primesieve.txt using
the a2x program from the asciidoc package. However when
packaging primesieve for e.g. a Linux distro it is recommended to
regenerate the man page.
# Build man page using a2x program (asciidoc package)
cmake -DBUILD_MANPAGE=ON .
cmake --build . --parallel