After many years of working exclusively in Unix environments, Windows experience appears daunting, in particular when it comes doing stuff in terminal. I have heard a lot of about the power of PowerShell, but I have never had enough motivation to explore it — I sticked to the familar Bash on Mac and Linux for most of my work. However, I was always interested in mastering the task of building C++ code using the native compiler on Windows (Visual C++) without using any GUI tools.
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 .
When it comes to building and installing OpenCV with Python support on *nix platforms, the collection of tutorials by Adrian Rosebrock is the best. He provides detailed description of the required steps, as well as motivation for better development practices. In particular, Adrian creates a dedicated virtualenv environment, installs NumPy in it, and builds the whole thing having this environment activated. Such a solution worked pretty well for me, both on Linux and macOS.