Writing you own C++ code with TRIQS

Basically, this structure means that you have successfully installed TRIQS in /home/triqs/install and that you plan to have your new project under /home/project. Obviously you can choose any other directory but this structure will be assumed below.

/home/triqs/install --> TRIQS is installed here
/home/project/src --> the sources of my project
/home/project/build --> the directory where I will compile my code

As we just said, we will start our project in a directory /home/project. We will have the sources in /home/project/src and later build (compile) the project in /home/project/build. Let’s start by writing some sources:

$ cd /home
$ mkdir project
$ cd project
$ mkdir src
$ cd src

OK, our project will be just one main.cpp file, e.g.:

#include <nda/nda.hpp>
using namespace nda;
int main(){
  array<double,1> A {1,2,3}, B{10,20,30}, C;
  C = A+B;
  std::cout << "C = "<< C << std::endl;
}

As you can see, the code includes headers from TRIQS. Along with main.cpp we write a CMakeLists.txt file to compile our project. In order to make this easy, there is a file called TRIQSConfig.cmake in /home/triqs/install/lib/cmake/triqs. Including this file in your CMakeLists.txt automatically defines a certain number of useful variables, especially the include directories related to the TRIQS headers and the location of the TRIQS libraries. Here is what your simple CMakeLists.txt can be:

# Start configuration
cmake_minimum_required(VERSION 2.8.12)
project(myproj CXX)
set(CMAKE_BUILD_TYPE Release)

# Load TRIQS, including all predefined variables from TRIQS installation
find_package(TRIQS REQUIRED)

# Create executable
add_executable(example main.cpp)

# Linking and include info
target_link_libraries(example triqs)
triqs_set_rpath_for_target(example)

We’re all set! Everything is ready to compile our project. If we want to build everything in /home/project/build, we do as follows:

$ cd /home/project
$ mkdir build
$ cd build
$ cmake -DTRIQS_PATH=/home/triqs/install /home/project/src
$ make
$ ./example

That’s it! You can modify your sources and then recompile with make. Obviously with bigger projects your CMakeLists.txt file will change, but the principle remains the same.

A simple C++ project, with its tests and documentation

Warning

TO BE WRITTEN

A mixed C++/Python project

Warning

TO BE WRITTEN