title: Very strange linker errors using matplotlib-cpp, how to even fix it?
body: <p>I'm working on C++ project for university (I can't choose Python, my professor decided like so) and I need to use matplotlib-cpp (<a href="https://github.com/lava/matplotlib-cpp" rel="nofollow noreferrer">https://github.com/lava/matplotlib-cpp</a>), I have a macBook with High Sierra 10.13.6 freshly installed and Xcode 10.1, so I did the following: </p>
  
  <ol>
  <li>Downloaded the zip from Github, unzipped and placed <code>matplotlibcpp.h</code> in my project folder.</li>
  <li>Got a couple errors about not finding libraries, so i fixed adding <code>Python/</code> before <code>Python/Python.h</code> and <code>/usr/local/include/include/</code> before <code>numpy/arrayobject.h</code>. This is what the first lines of the library <code>matplotlibcpp.h</code> look like now:</li>
  </ol>
  
  <pre><code>#pragma once
  
  #include &lt;algorithm&gt;
  #include &lt;array&gt;
  #include &lt;cstdint&gt; // &lt;cstdint&gt; requires c++11 support
  #include &lt;functional&gt;
  #include &lt;iostream&gt;
  #include &lt;unordered_map&gt;
  #include &lt;map&gt;
  #include &lt;numeric&gt;
  #include &lt;stdexcept&gt;
  #include &lt;unordered_map&gt;
  #include &lt;vector&gt;
  
  #include &lt;Python/Python.h&gt;
  
  #ifndef WITHOUT_NUMPY
  #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
  #include &lt;/usr/local/include/include/numpy/arrayobject.h&gt;
  </code></pre>
  
  <ol start="3">
  <li><code>#include "matplotlibcpp.h"</code> and got it to compile and run showing zero errors using <code>-std=c++17</code> without adding any specific matplotlib functions, I've done it this way:</li>
  </ol>
  
  <pre><code>#include "matplotlibcpp.h"
  
  using namespace std;
  
  namespace plt = matplotlibcpp;
  
  int main(...) {
    ...
  }
  </code></pre>
  
  <ol start="4">
  <li>Now when i add any function such as <code>plt::plot({1,2,3,4})</code> it compiles and gives me linker error in clang, it tells me:</li>
  </ol>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "_PyCObject_AsVoidPtr", referenced from:
        _import_array() in main.o
    "_PyCObject_Type", referenced from:
        _import_array() in main.o
    "_PyErr_Format", referenced from:
        _import_array() in main.o
    "_PyErr_Print", referenced from:
        matplotlibcpp::detail::_interpreter::_interpreter() in main.o
        matplotlibcpp::detail::_interpreter::import_numpy() in main.o
    "_PyErr_SetString", referenced from:
        matplotlibcpp::detail::_interpreter::import_numpy() in main.o
        _import_array() in main.o
    "_PyExc_AttributeError", referenced from:
        _import_array() in main.o
    "_PyExc_ImportError", referenced from:
        matplotlibcpp::detail::_interpreter::import_numpy() in main.o
    "_PyExc_RuntimeError", referenced from:
        _import_array() in main.o
    "_PyFunction_Type", referenced from:
        matplotlibcpp::detail::_interpreter::safe_import(_object*, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;) in main.o
    "_PyImport_Import", referenced from:
        matplotlibcpp::detail::_interpreter::_interpreter() in main.o
    "_PyImport_ImportModule", referenced from:
        _import_array() in main.o
    "_PyObject_CallMethod", referenced from:
        matplotlibcpp::detail::_interpreter::_interpreter() in main.o
    "_PyObject_CallObject", referenced from:
        bool matplotlibcpp::plot&lt;double, double&gt;(std::__1::vector&lt;double, std::__1::allocator&lt;double&gt; &gt; const&amp;, std::__1::vector&lt;double, std::__1::allocator&lt;double&gt; &gt; const&amp;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;) in main.o
    "_PyObject_GetAttrString", referenced from:
        matplotlibcpp::detail::_interpreter::safe_import(_object*, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt;) in main.o
        _import_array() in main.o
    "_PyString_FromString", referenced from:
        bool matplotlibcpp::plot&lt;double, double&gt;(std::__1::vector&lt;double, std::__1::allocator&lt;double&gt; &gt; const&amp;, std::__1::vector&lt;double, std::__1::allocator&lt;double&gt; &gt; const&amp;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;) in main.o
        matplotlibcpp::detail::_interpreter::_interpreter() in main.o
    "_PyTuple_New", referenced from:
        bool matplotlibcpp::plot&lt;double, double&gt;(std::__1::vector&lt;double, std::__1::allocator&lt;double&gt; &gt; const&amp;, std::__1::vector&lt;double, std::__1::allocator&lt;double&gt; &gt; const&amp;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;) in main.o
        matplotlibcpp::detail::_interpreter::_interpreter() in main.o
    "_PyTuple_SetItem", referenced from:
        bool matplotlibcpp::plot&lt;double, double&gt;(std::__1::vector&lt;double, std::__1::allocator&lt;double&gt; &gt; const&amp;, std::__1::vector&lt;double, std::__1::allocator&lt;double&gt; &gt; const&amp;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;) in main.o
    "_Py_Finalize", referenced from:
        matplotlibcpp::detail::_interpreter::~_interpreter() in main.o
    "_Py_Initialize", referenced from:
        matplotlibcpp::detail::_interpreter::_interpreter() in main.o
    "_Py_SetProgramName", referenced from:
        matplotlibcpp::detail::_interpreter::_interpreter() in main.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  
  </code></pre>
  
  <pre><code>symbol(s) not found for architecture x86_64
  
  linker command failed with exit code 1 (use -v to see invocation)
  
  Ld /Users/giovannigravili/Library/Developer/Xcode/DerivedData/brain-3.X-hclmildbujzoynbfpgamcnjyrxig/Build/Products/Debug/brain-3.X normal x86_64 (in target: brain-3.X)
      cd /Users/giovannigravili/Documents/GitHub/brain_project/brain-3.X
      export MACOSX_DEPLOYMENT_TARGET=10.14
      /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -L/Users/giovannigravili/Library/Developer/Xcode/DerivedData/brain-3.X-hclmildbujzoynbfpgamcnjyrxig/Build/Products/Debug -F/Users/giovannigravili/Library/Developer/Xcode/DerivedData/brain-3.X-hclmildbujzoynbfpgamcnjyrxig/Build/Products/Debug -filelist /Users/giovannigravili/Library/Developer/Xcode/DerivedData/brain-3.X-hclmildbujzoynbfpgamcnjyrxig/Build/Intermediates.noindex/brain-3.X.build/Debug/brain-3.X.build/Objects-normal/x86_64/brain-3.X.LinkFileList -mmacosx-version-min=10.14 -Xlinker -object_path_lto -Xlinker /Users/giovannigravili/Library/Developer/Xcode/DerivedData/brain-3.X-hclmildbujzoynbfpgamcnjyrxig/Build/Intermediates.noindex/brain-3.X.build/Debug/brain-3.X.build/Objects-normal/x86_64/brain-3.X_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/giovannigravili/Library/Developer/Xcode/DerivedData/brain-3.X-hclmildbujzoynbfpgamcnjyrxig/Build/Intermediates.noindex/brain-3.X.build/Debug/brain-3.X.build/Objects-normal/x86_64/brain-3.X_dependency_info.dat -o /Users/giovannigravili/Library/Developer/Xcode/DerivedData/brain-3.X-hclmildbujzoynbfpgamcnjyrxig/Build/Products/Debug/brain-3.X
  </code></pre>
  
  <p>I got an example compiling through g++ on my terminal using <code>-I</code>,<code>-l</code> flags, it doesn't run though, it says <code>ImportError:</code>. How do I solve this? Thank you kind stranger.</p>
  
  <p><strong>Edit 1:</strong></p>
  
  <p>I modified the header referencing to the libraries, Xcode now gives me the same warnings (deprecated <code>register</code> use) and error (linker) the compiler does, and now it looks like this,: </p>
  
  <pre><code>#pragma once
  
  #include &lt;algorithm&gt;
  #include &lt;array&gt;
  #include &lt;cstdint&gt; // &lt;cstdint&gt; requires c++11 support
  #include &lt;functional&gt;
  #include &lt;iostream&gt;
  #include &lt;unordered_map&gt;
  #include &lt;map&gt;
  #include &lt;numeric&gt;
  #include &lt;stdexcept&gt;
  #include &lt;unordered_map&gt;
  #include &lt;vector&gt;
  
  #include &lt;/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h&gt;
  
  #ifndef WITHOUT_NUMPY
  #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
  #include &lt;/usr/local/include/include/numpy/arrayobject.h&gt;
  </code></pre>