Setup¶
This document describes how to set up a development environment for the course. All course source code is available at:
It is also possible to use the following link for a web based setup in compiler explorer:
Quick start (recommended)¶
If you already have a C++ compiler and CMake installed, this is the fastest way to get started:
git clone https://github.com/NAISS-Training/array-computing.git
cd array-computing
cmake -S . -B build-release -DCMAKE_BUILD_TYPE=Release
cmake --build build-release
Minimum requirements¶
- C++ compiler with C++23 support (recommended: GCC 14 or newer, Clang 15 or newer, MSVC 19.36 or newer)
- CMake (recommended: 3.24 or newer)
- Eigen 3.4.x
Optional:
make(only needed for the Makefile-based workflow)vcpkg(if your CMake setup uses it for dependency management)
Building with CMake (cross-platform)¶
This is the default and recommended workflow for all platforms.
1. Clone the repository¶
2. Configure and build (Debug)¶
3. Configure and build (Release)¶
vcpkg notes¶
If your local CMakeLists.txt integrates with vcpkg, install and bootstrap vcpkg first:
Typical configure command when a toolchain file is needed:
cmake -S . -B build-release -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=<path-to-vcpkg>/scripts/buildsystems/vcpkg.cmake
If your repository already wires this automatically, you can use the standard configure command shown above.
Building with Make (Linux/macOS)¶
If you prefer Make and have all prerequisites installed:
The Makefile builds all configured examples in src.
Platform-specific setup¶
Linux (Ubuntu)¶
Ubuntu 24.04 note
Ubuntu 24.04 commonly ships GCC 13 by default. While -std=c++23 is accepted,
libstdc++ 13 may not provide all C++23 library headers (notably <print>), which can cause:
fatal error: print: No such file or directory
If you hit this, install and use GCC 14 (or newer).
Install tools:
Validate both default compiler and GCC 14:
Build with GCC 14 explicitly (recommended on Ubuntu 24.04 when using C++23 library features such as <print>):
Optional: for a Makefile-based build, keep system defaults unchanged and set compiler per command:
Optional: switch system-wide default gcc/g++ using update-alternatives:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 130
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 140
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 130
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 140
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
Validate tools:
Validate Eigen installation with a minimal test:
Create ex0.cpp:
#include <iostream>
#include <Eigen/Dense>
int main()
{
Eigen::Matrix3d m = Eigen::Matrix3d::Random();
std::cout << "Here is the matrix m:" << std::endl;
std::cout << m << std::endl;
return 0;
}
Compile and run:
macOS¶
Install tools using Homebrew:
Create ex0.cpp:
#include <iostream>
#include <Eigen/Dense>
int main()
{
Eigen::Matrix3d m = Eigen::Matrix3d::Random();
std::cout << "Here is the matrix m:" << std::endl;
std::cout << m << std::endl;
return 0;
}
Compile and run (Apple Silicon):
Compile and run (Intel):
Windows¶
Two supported workflows:
Option A: WSL (recommended)¶
- Install WSL and Ubuntu.
- Open an Ubuntu terminal in WSL.
- Follow the Linux setup instructions in this document.
Option B: Visual Studio + CMake¶
- Install Visual Studio with the Desktop development with C++ workload.
- Install CMake (if not already available from Visual Studio tools).
- Install Eigen using
vcpkgor another package manager. - Use the x64 Native Tools Command Prompt for VS and run:
git clone https://github.com/NAISS-Training/array-computing.git
cd array-computing
cmake -S . -B build-release -DCMAKE_BUILD_TYPE=Release
cmake --build build-release
If your generator is multi-config (for example Visual Studio), use:
Using COSMOS at LUNARC¶
If you have an account at LUNARC, you can log in via remote desktop or SSH:
Load a suitable environment:
Validate tools:
Validate Eigen with the same ex0.cpp test shown above. Compile and run:
Template for course exercises¶
The template folder contains a simple Eigen project and a Makefile.
Add your C++ file there and build it with the provided Makefile.
Troubleshooting¶
- Eigen not found: verify Eigen installation path and include directory (
-I.../eigen3) or usevcpkgtoolchain with CMake. fatal error: print: No such file or directoryon Ubuntu 24.04: GCC 13/libstdc++ may not yet ship<print>. Installgcc-14/g++-14and compile withg++-14(ormake CXX=g++-14).- Compiler does not support C++23: check
g++ --version(or your compiler version) and install a newer toolchain. - CMake configure fails after dependency changes: remove the build directory and configure again.
- Wrong generator/toolchain on Windows: run from the correct Visual Studio developer prompt or use WSL.
Verification checklist¶
g++ --version(or equivalent) workscmake --versionworks- CMake configure step completes successfully
- Build step completes successfully
- At least one program runs without errors