A few notes on the compilers and libraries used by the C++ examples. The Linux instructions cover Debian, Ubuntu, and Red Hat Enterprise Linux (RHEL), followed by macOS. The examples use C++23, although they do not necessarily rely on C++23-specific features.
Linux (Debian, Ubuntu, and Red Hat)¶
C++ compilers¶
GCC is a straightforward choice for compiling the examples. Install the usual build tools if needed.
Debian or Ubuntu:
sudo apt install build-essentialRed Hat Enterprise Linux:
sudo dnf group install "Development Tools"Check which compiler is being used:
which g++
g++ --versionClang is another option if installed:
which clang++
clang++ --versionFor an example that uses no additional libraries:
g++ -std=c++23 example.cpp -o exampleThe available C++23 features depend on the compiler and its standard library. In particular, RHEL 9’s system GCC is older; a newer GCC Toolset may be needed for -std=c++23 and newer language features.
HDF5¶
HDF5 includes h5c++, a wrapper that supplies the compiler and linking options needed by its C++ interface.
Debian or Ubuntu:
sudo apt install libhdf5-devRed Hat Enterprise Linux:
sudo dnf install hdf5-develOn RHEL 9, hdf5-devel is available through EPEL, which may need to be enabled first (see Red Hat’s EPEL setup guidance).
Inspect the installed wrapper:
which h5c++
h5c++ -show
h5c++ -showconfigwhich h5c++shows which installation is being used.h5c++ -showprints the underlying compiler command, including include paths and libraries.h5c++ -showconfigreports the HDF5 build configuration.
Compile the HDF5 example with:
h5c++ -std=c++23 inspect_hdf5.cpp -o inspect_hdf5The wrapper may use GCC or another compiler, depending on how HDF5 was built. Check -show rather than assuming.
XML and pugixml¶
The XML example uses pugixml. Install its development package.
Debian or Ubuntu:
sudo apt install libpugixml-devRed Hat Enterprise Linux:
sudo dnf install pugixml-develOn RHEL 9, pugixml-devel is available through EPEL.
Then compile with:
g++ -std=c++23 inspect_xml.cpp -o inspect_xml -lpugixmlThese packages install headers and libraries in standard system locations, so extra -I and -L options are normally unnecessary.
macOS¶
C++ compilers¶
Apple Clang is available through Xcode or Apple’s command-line developer tools. To inspect the compiler selected by those tools:
xcrun --find clang++
xcrun clang++ --versionMacPorts can also provide GCC, with versioned executable names. For GCC 15:
which g++-mp-15
g++-mp-15 --versionA Conda environment may provide another Clang compiler. Check the executable name shown by a library’s compiler wrapper; in one openmc-env installation, h5c++ -show uses arm64-apple-darwin20.0.0-clang++.
For a standalone C++ example using Apple Clang:
clang++ -std=c++23 example.cpp -o exampleHDF5¶
In the openmc-env Conda environment, HDF5 provides h5c++. Activate the environment and inspect the wrapper:
conda activate openmc-env
which h5c++
h5c++ -show
h5c++ -showconfigHere, h5c++ -show identifies the Conda compiler and the HDF5 libraries and paths supplied automatically. The precise flags depend on the environment; there is no need to copy them into the build command.
Compile the HDF5 example with:
h5c++ -std=c++23 inspect_hdf5.cpp -o inspect_hdf5h5c++ is a compiler wrapper, not a separate C++ compiler. Its underlying compiler may differ from the one returned by which clang++.
XML and pugixml¶
In this macOS setup, pugixml is installed through MacPorts. Check the installation:
port installed pugixmlCompile the XML example with Apple Clang:
clang++ -std=c++23 inspect_xml.cpp -o inspect_xml \
-I/opt/local/include -L/opt/local/lib -lpugixmlHere:
-I/opt/local/includegives the compiler the location ofpugixml.hpp.-L/opt/local/libgives the linker the library directory.-lpugixmllinks the pugixml library.
An error about a missing pugixml.hpp usually indicates an include-path issue. Undefined pugixml symbols at link time usually indicate a missing or incorrect library option.
The HDF5 and pugixml examples use different installations here—Conda for HDF5 and MacPorts for pugixml—so their build commands are kept separate.