Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to link C lib against python for embedding under Windows?
    text
    copied!<p>I am working on an application written in C. One part of the application should embed python and there is my current problem. I try to link my source to the Python library but it does not work.</p> <p>As I use MinGW I have created the python26.a file from python26.lib with dlltool and put the *.a file in <code>C:/Program Files (x86)/python/2.6/libs</code>.</p> <p>Therefore, I compile the file with this command:</p> <pre><code>gcc -shared -o mod_python.dll mod_python.o "-LC:\Program Files (x86)\python\2.6\libs" -lpython26 -Wl,--out-implib,libmod_python.a -Wl,--output-def,mod_python.def </code></pre> <p>and I get those errors:</p> <pre><code>Creating library file: libmod_python.a mod_python.o: In function `module_init': mod_python.c:34: undefined reference to `__imp__Py_Initialize' mod_python.c:35: undefined reference to `__imp__PyEval_InitThreads' ... and so on ... </code></pre> <ul> <li>My Python "root" folder is <code>C:\Program Files (x86)\python\2.6</code></li> <li>The Devsystem is a Windows Server 2008</li> <li>GCC Information: <code>Reading specs from C:/Program Files (x86)/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug Thread model: win32 gcc version 3.4.5 (mingw-vista special r3)</code></li> </ul> <p>What I do wrong? How I get it compiled and linked :-)?</p> <p>Cheers, gregor</p> <hr> <p><strong>Edit:</strong> I forgot to write information about my Python installation: It's the official python.org installation 2.6.1</p> <p>... and how I created the python.a file:</p> <pre><code>dlltool -z python.def --export-all-symbols -v c:\windows\system32\python26.dll dlltool --dllname c:\Windows\system32\python26.dll --def python.def -v --output-lib python26.a </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload