c++

Position independent code

In this blog post, I am going to provide a short overview of the concept of position independent code and its specification in CMake, particularly in projects using pybind11. Some time ago, when I was working on the FxIS project, which was developed in C++ with the additional Python extension realized with pybind11, I encountered a linking error, which included a line similar to this: /usr/bin/ld: libcore.a(sum.cpp.o): relocation R_X86_64_PC32 against symbol .

C++ move semantics

In the modern versions of C++ (starting from C++11) one encounters a concept of move semantics. It may confusing a bit, and in this post I am going to provide my notes on the topic (mostly based on Bjarne Stroustrup’s The C++ Programming Language (4th edition): sections 3.3, 7.7.2, 17.5.2). The first important concept is rvalue reference. For a type T, a rvalue reference is T&& (note the double ampresand). It basically represents a reference to a temporary object that is assumed to be modified and not used again.

Exposing C++ array data in Python with the Pybind11 buffer protocol

Python works great together with native code. The success of the Python data science stack is largely attributed to the capability of building native extensions. It is no secret, however, that the out-of-the-box C-based facilities are rather cumbersome to use. Luckily, there are a bunch of alternatives out there. The one I liked the most is Pybind11, a fork of Boost.Python with focus on the modern C++ standards. It is distributed as a lightweight header-only library that can be bundled with your project.