7/14/2016

Compile my C/C++ program with certain version of Python interpreter

If you have more than two Pythons in your system, such as in the case that Python2 and Python3 are installed in your system, you may have to specify one explicitly to compile that with your application program, which is written not in Python. Here is how to specify PythonX.Y with the python version number X.Y in a Makefile to build your application.

First, you need to find out compiler and linker options specified at the time of installation of PythonX.Y:

% pythonX.Y-config --cflags

will show you the compiler options <CFLAGS> and

% pythonX.Y-config --ldflags

will show you the linker options <LDFLAGS>.

Second, you add lines in the Makefile to include <CFLAGS> in the compilation and load <LDFLAGS> in the linkage.

That's it!