Skip to content

Developer notes

Thomas Nipen edited this page Jun 15, 2021 · 3 revisions

How does the python pacakge get built?

To build the python package, you should just need to run "make install-python-user". This basically does the following

  1. compiles the C++ code into .o files (CMakeFiles/titanlib.dir/src/*.cpp.o)
  2. runs SWIG on the titanlib.h file, which creates the autogenerated file CMakeFiles/_titanlib.dir/titanlibPYTHON_wrap.cxx as well as the python module file extras/SWIG/python/titanlib.py
  3. links the titanlibPYTHON_wrap.cxx with the C++ .o files from 1) producing _titanlib.so

_titanlib.so together with titanlib.py is a fully functioning python package that gets installed into your python environment (probably ~/.local/lib/python*/site-packages/ if on linux).

Segmentation fault after adding a new function

Importing the titanlib package in python can sometimes give a segmentation fault. This typically happens if there is a function declaration in titanlib.h that is not defined in any of the .cpp files. Two common reasons are:

  1. After added a new .cpp file, cmake must be rerun so that the makefile knows of its existence.
  2. The new function declaration in titanlib.h doesn't match exactly the definition in a .cpp file (e.g. the input arguments differ). To find undefined functions, use something like nm build/extras/SWIG/python/_titanlib.so | c++filt | grep " U " | grep "titanlib"