On Tue, Dec 29, 2009 at 5:20 PM, Dan Stromberg <[email protected]> wrote:
>
> I'm trying to create a little standalone executable to help troubleshoot a
> problem on a windows system.  The intent is not (necessarily) to have a fast
> program, but rather to have a single .exe without a bunch of dll's, so we
> don't have to copy more than one new file onto this production server.
>

Take all my comments with care, I have very littly Win experience.

1) If you want a self-contained exe without any dependency on Python's
DLL, then you definitely need to use a static library.

2) But if you use a static library, then I bet you have to #define
Py_NO_ENABLE_SHARED or something like that (better to pass an
appropriate option on the command line adding stuff to CFLAGS at your
makefile), in order to make PyAPI_FUNC and PyAPI_DATA macros (in
pyport.h) to adjust for the static library case. Other way could be to
use a custom pyport.h, but IMHO #define Py_NO_ENABLE_SHARED is by far
cleaner and easier


Hope that help. Please let all as know about your success/failure.

> Here's my (cygwin) Makefile:
>
> CFLAGS=-Ic:/Python26/include
> #LDFLAGS=-static -Lc:/Python26/libs -lpython26
> LDFLAGS=-Lc:/Python26/libs -lpython26
> CC=/cygdrive/c/MinGW/bin/gcc
> PYTHON=/cygdrive/c/Python26/python
> CYTHON=c:/Python26/Scripts/cython.py
> V=python26
>
> #CFLAGS=-Ic:/Python26/include
> #LDFLAGS=-static -L. -lpython26
> ##LDFLAGS=-L. -lpython26
> #CC=/cygdrive/c/MinGW/bin/gcc
> #PYTHON=/cygdrive/c/Python26/python
> #CYTHON=c:/Python26/Scripts/cython.py
> #V=python26
>
> #lib$V.a: /cygdrive/c/Python26/libs/$V.lib
> #       "$(HOME)/bin/pexports" c:/Python26/libs/$V.dll > $V.def
> #       dlltool --dllname $V.dll --def $V.def --output-lib lib$V.a
>
> seconds.exe: seconds.o # lib$V.a
>         $(CC) $(LDFLAGS) -o seconds.exe seconds.o
>
> seconds.o: seconds.c
>         $(CC) -c $(CFLAGS) seconds.c
>
> seconds.c: seconds.pyx
>         $(PYTHON) $(CYTHON) --embed seconds.pyx
>
> clean:
>         rm -f *.o *.exe *.c
>
> Things are OK until the link is attempted, at which point I get:
> /cygdrive/c/MinGW/bin/gcc -Lc:/Python26/libs -lpython26 -o seconds.exe
> seconds.o
>
> seconds.o:seconds.c:(.text+0x6f): undefined reference to
> `_imp__PyInt_FromLong'
> seconds.o:seconds.c:(.text+0x124): undefined reference to
> `_imp__PyTuple_New'
> seconds.o:seconds.c:(.text+0x1b8): undefined reference to
> `_imp__Py_InitModule4'
> seconds.o:seconds.c:(.text+0x200): undefined reference to
> `_imp__PyImport_AddMod
> ule'
> seconds.o:seconds.c:(.text+0x253): undefined reference to
> `_imp__PyObject_SetAtt
> rString'
> seconds.o:seconds.c:(.text+0x2a5): undefined reference to
> `_imp__PyObject_SetAtt
> rString'
>
> It goes on like that for quite a while, about a bunch of _imp__ functions
> being missing.
>
> Do I need to build my program with the same C compiler that my Python
> distribution was built with?
>
> I saw the FAQ about needing to build a libpython26.a, but 1) I have one
> already, and 2) pexports errored.  I also googled quite a bit and didn't
> find anything that looked quite relevant.
>
> I'm using Python 2.6.4 from python.org on Windows XP SP3, Dave Cournapeau's
> Cython 0.11.2 installer for Python26, and MinGW (native gcc) 5.1.6.  I'm
> using Cygwin make, but the rest is intended to be non-cygwin (though if a
> static cygwin executable will run without cygwin, that might work for me
> too).
>
> BTW, does distutils support building a --embed executable?
>
> Any suggestions?
>
> TIA!
>
> --
> Dan Stromberg
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>
>



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to