title: Undefined Symbol Error with embedded Python interpreter
body: <p>Originally I had this error within a larger project with pybind11 to embed an anaconda Python interpreter.
  I was able to boil it down and reproduce the error with just a simple minimal example.</p>
  
  <p>When I run my executable (which embeds python), I obtain this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;string&gt;", line 3, in &lt;module&gt;
    File "/app/Python-3.8.2-build/lib/python3.8/struct.py", line 13, in &lt;module&gt;
      from _struct import *
  ImportError: /app/Python-3.8.2-build/lib/python3.8/lib-dynload/_struct.cpython-38-x86_64-linux-gnu.so: undefined symbol: PyByteArray_Type
  </code></pre>
  
  <p>At first, I built Python-3.8.2 from source. Then I compiled an executable from the following C code:</p>
  
  <pre><code>#include &lt;Python.h&gt;
  
  int main(int argc, char *argv[])
  {
      Py_Initialize();
      PyRun_SimpleString("import struct");
      if (Py_FinalizeEx() &lt; 0) {
          exit(120);
      }
      return 0;
  }
  </code></pre>
  
  <p>using this command:</p>
  
  <pre><code>gcc -o execpy execpy.c \
  -I/app/Python-3.8.2-build/include/python3.8 \
  -Wno-unused-result -Wsign-compare  -DNDEBUG -g -fwrapv -O3 \
  -L/app/Python-3.8.2-build/lib  -lcrypt -lpthread -ldl  -lutil -lm \
  /app/Python-3.8.2/libpython3.8.a
  </code></pre>
  
  <p>Then simply execute <code>./execpy</code> gives the error from above... Any ideas?</p>
  
  <p><strong>EDIT</strong>: In this example I want to link <code>libpython</code> statically just like the python interpreter does not depend on any libpython.so.</p>
  
  <p><strong>EDIT</strong>: <code>_struct.*.so</code> does not seem to have dependencies to libpython linked in (this is the same for my standard anaconda python interpreter):</p>
  
  <pre><code>$ ldd /app/Python-3.8.2-build/lib/python3.8/lib-dynload/_struct.cpython-38-x86_64-linux-gnu.so
      linux-vdso.so.1 =&gt;  (0x00007fff32bf0000)
      libpthread.so.0 =&gt; /lib64/libpthread.so.0 (0x00007f71a5634000)
      libc.so.6 =&gt; /lib64/libc.so.6 (0x00007f71a5266000)
      /lib64/ld-linux-x86-64.so.2 (0x00007f71a5a5c000)
  </code></pre>
  
  <p>I also checked the <code>_struct.*.so</code> of my system python interpreter on a different machine and it has it:</p>
  
  <pre><code>    linux-vdso.so.1 =&gt;  (0x00007ffe2b3d9000)
      libpython3.6m.so.1.0 =&gt; /lib64/libpython3.6m.so.1.0 (0x00007febe24fd000)
      libpthread.so.0 =&gt; /lib64/libpthread.so.0 (0x00007febe22e1000)
      libc.so.6 =&gt; /lib64/libc.so.6 (0x00007febe1f13000)
      libdl.so.2 =&gt; /lib64/libdl.so.2 (0x00007febe1d0f000)
      libutil.so.1 =&gt; /lib64/libutil.so.1 (0x00007febe1b0c000)
      libm.so.6 =&gt; /lib64/libm.so.6 (0x00007febe180a000)
      /lib64/ld-linux-x86-64.so.2 (0x00007febe2c30000)
  </code></pre>