title: Compile Python code to statically linked executable with Cython
body: <p>I have a pure Python script that I would like to distribute to systems with unkown Python configuration. Therefore, I would like to compile the Python code to a stand-alone executable.</p>
  
  <p>I run <code>cython --embed ./foo.py</code> without problems giving <code>foo.c</code>. Then, I run</p>
  
  <pre><code>gcc $(python3-config --cflags) $(python3-config --ldflags) ./foo.c
  </code></pre>
  
  <p>where <code>python3-config --cflags</code> gives</p>
  
  <pre><code>-I/usr/include/python3.5m -I/usr/include/python3.5m  -Wno-unused-result -Wsign-compare -g -fdebug-prefix-map=/build/python3.5-MLq5fN/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security  -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
  </code></pre>
  
  <p>and <code>python3-config --ldflags</code> gives</p>
  
  <pre><code>-L/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu -L/usr/lib -lpython3.5m -lpthread -ldl  -lutil -lm  -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions
  </code></pre>
  
  <p>This way I obtain a dynamically linked executable that runs without a problem. <code>ldd a.out</code> yields</p>
  
  <pre><code> linux-vdso.so.1 (0x00007ffcd57fd000)
   libpython3.5m.so.1.0 =&gt; /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 (0x00007fda76823000)
   libpthread.so.0 =&gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fda76603000)
   libdl.so.2 =&gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fda763fb000)
   libutil.so.1 =&gt; /lib/x86_64-linux-gnu/libutil.so.1 (0x00007fda761f3000)
   libm.so.6 =&gt; /lib/x86_64-linux-gnu/libm.so.6 (0x00007fda75eeb000)
   libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007fda75b4b000)
   libexpat.so.1 =&gt; /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007fda7591b000)
   libz.so.1 =&gt; /lib/x86_64-linux-gnu/libz.so.1 (0x00007fda756fb000)
   /lib64/ld-linux-x86-64.so.2 (0x00007fda77103000)
  </code></pre>
  
  <p>Now, I try to add the option <code>-static</code> to gcc, but this results in an error:</p>
  
  <pre><code>/usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>I checked that all shared libraries given by ldd are also installed as static libraries. </p>
  
  <p>So, is this some incompatibility with the options given by python3-config?</p>