1
0
Эх сурвалжийг харах

Document flag for changing python version, make the mechanism more general

Benno Evers 8 жил өмнө
parent
commit
a284aa557e
2 өөрчлөгдсөн 22 нэмэгдсэн , 4 устгасан
  1. 16 1
      README.md
  2. 6 3
      matplotlibcpp.h

+ 16 - 1
README.md

@@ -103,7 +103,22 @@ The C++-part of the library consists of the single header file `matplotlibcpp.h`
 anywhere.
 Since a python interpreter is opened internally, it is necessary to link against `libpython2.7` in order to use
 matplotlib-cpp.
-(There should be no problems using python3 instead of python2.7, if desired)
+
+# Python 3
+
+The code is written in a way that should support both python2 and python3.
+By default, matplotlib-cpp will try to "just work" and include the header `python2.7/Python.h`.
+
+To modify this behaviour the define `MATPLOTLIBCPP_PYTHON_HEADER`,
+can be set to an absolute or relative path: 
+
+     #define MATPLOTLIBCPP_PYTHON_HEADER /usr/include/python3.6/Python.h
+     #include "matplotlibcpp.h"
+
+or
+
+    g++ -DMATPLOTLIBCPP_PYTHON_HEADER=Python.h -I/usr/include/python3.6 <...>
+
 
 Why?
 ----

+ 6 - 3
matplotlibcpp.h

@@ -10,9 +10,12 @@
 #include <functional>
 #endif
 
-#ifdef PY_INCLUDE
-#include <Python.h>
-#else
+// i.e. g++ -DMATPLOTLIBCPP_PYTHON_HEADER=/usr/include/python3.6/Python.h [...]
+#ifdef MATPLOTLIBCPP_PYTHON_HEADER
+#define STRINGIFY_(x) #x
+#define STRINGIFY(x) STRINGIFY_(x)
+#include STRINGIFY(MATPLOTLIBCPP_PYTHON_HEADER)
+#else // This should stay the default for backwards compatibility
 #include <python2.7/Python.h>
 #endif