libftdi Archives

Subject: Re: windows 7 Python modules

From: Joachim Schambach <jschamba@xxxxxxxxxxxxxxxxxx>
To: <libftdi@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 24 Oct 2014 10:54:45 -0500
OK, thanks for all the responses.
I tried around a little, but i think i am still missing something very fundamental in the MinGW setup or something like that.
So let me try to be a little more specific:

The module that works just fine under Linux is called ftdIOmodule.c, which in turn calls all kinds of functions from libftdi. I tried to modify the "setup.py" file to correspond to the appropriate Windows files, and came up with something like this:

---- setup.py -----
from distutils.core import setup, Extension
 
module1 = Extension('ftdIO',
                    include_dirs = ['../../../FTDI_USB/libftdi1-1.1_devkit_x86_x64_21Feb2014/include/libftdi1'],
                    libraries = ['ftdi1'],
                    library_dirs = ['../../../FTDI_USB/libftdi1-1.1_devkit_x86_x64_21Feb2014/lib64'],
                    define_macros=[('MS_WIN64', 1)],
                    sources = ['ftdIOmodule.c'])
 
setup (name = 'PackageName',
        version = '1.1',
        description = 'ftdIO functions for Python',
        ext_modules = [module1])
---- end setup.py ---------

I then tried to compile this with the command line:

python setup_windows.py build -c mingw32

and that's when I saw all kinds of error messages:

running build
running build_ext
building 'ftdIO' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -DMS_WIN64=1 -I../../../FTDI_USB/libftdi1-1.
1_devkit_x86_x64_21Feb2014/include/libftdi1 -IC:\Python27\include -IC:\Python27\
PC -c ftdIOmodule.c -o build\temp.win-amd64-2.7\Release\ftdiomodule.o
ftdIOmodule.c: In function 'writeMemFromFile':
ftdIOmodule.c:153:3: warning: implicit declaration of function 'getline' [-Wimpl
icit-function-declaration]
   if((bytes_read = getline(&line, &nbytes, fr)) > 0) {
   ^
writing build\temp.win-amd64-2.7\Release\ftdIO.def
creating build\lib.win-amd64-2.7
C:\MinGW\bin\gcc.exe -shared -s build\temp.win-amd64-2.7\Release\ftdiomodule.o build\temp.win-amd64-2.7\Release\ftdIO.def -L../../../FTDI_USB/libftdi1-1.1_devkit_x86_x64_21Feb2014/lib64 -LC:\Python27\libs -LC:\Python27\PCbuild\amd64 -lftdi1 -lpython27 -lmsvcr90 -o build\lib.win-amd64-2.7\ftdIO.pyd
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0x32): undefined reference to `_imp__Py_InitModule4_64'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0x43): undefined reference to `ftdi_new'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0x71): undefined reference to `ftdi_usb_open_desc'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0x91): undefined reference to `ftdi_set_bitmode'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0xa9): undefined reference to `ftdi_set_latency_timer'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0xd5): undefined reference to `_imp__PyArg_ParseTuple'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0xf3): undefined reference to `_imp__PyExc_RuntimeError'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0xfe): undefined reference to `_imp__PyErr_SetString'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0x146): undefined reference to `_imp__PyExc_NameError'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0x151): undefined reference to `_imp__PyErr_SetString'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0x15d): undefined reference to `_imp___Py_NoneStruct'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0x186): undefined reference to `ftdi_usb_close'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0x196): undefined reference to `ftdi_free'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0x1eb): undefined reference to `_imp__PyArg_ParseTuple'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0x22d): undefined reference to `_imp__PyExc_RuntimeError'
build\temp.win-amd64-2.7\Release\ftdiomodule.o:ftdIOmodule.c:(.text+0x238): undefined reference to `_imp__PyErr_SetString'
....

and so on
I kind of understand the warning about the getline function, but it looks like none of the "Python" or "libftdi" functions are found by gcc in the libraries you provided?

So what am I missing? Since Python is probably compiled by MS Visual Studio, maybe that explains all the missing symbols from Python.

Very puzzled,

Jo

On 10/24/2014 1:48 AM, xantares 09 wrote:
Hi,

You dont have to deal with the hassle of visual studio crap, you can cross-compile libftdi and it's python module using mingw,
it then can be loaded in the native python interpreter and any other even if the interpreter itself is compiled with msvc.
You'll have to provide libftdi & libusb mingw dlls (and of course libftdi's pyd) along the module.

This will be interesting to you:
https://aur.archlinux.org/packages/mingw-w64-libusb/
https://aur.archlinux.org/packages/mingw-w64-libftdi/

xan.

> Date: Fri, 24 Oct 2014 09:52:40 +0800
> Subject: Re: windows 7 Python modules
> From: xiaofanc@xxxxxxxxx
> To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
>
> On Thu, Oct 23, 2014 at 10:05 PM, Joachim Schambach
> <jschamba@xxxxxxxxxxxxxxxxxx> wrote:
> > I have written a Python module ("extension") in Linux using code that calls
> > libftdi functions and successfully built it using the Python setup tools. Now I
> > am trying to port this to a Windows 7 machine, but am a little lost on how to
> > best go about this. A first attempt on compiling the same module under the
> > ActivePython distribution in Windows seems to want to use Microsoft Visual
> > Studio as the compiler. I did not see any version of libftdi compiled for that,
> > so do I first need to figure out how to compile the library itself under Windows
> > or is there a precompiled binary somewhere? I assume somehow I will also need
> > libusb for windows, so how do I go about that?
> > sorry if these are some very basic questions, but I couldn't find any writeup on
> > how to best go about this. The README only seems to indicate using mingw, but I
> > don't know how to combine this with the Python distribution under Windows.
> > Any help would be greatly appreciated.
> > Cheers,
> > Jo
>
> I have compiled libftdi using MinGW (both 32bit MinGW.org and the 32/64bit
> MinGW-w64 toolchain) under Windows.
>
> http://sourceforge.net/projects/picusb/files/
>
> On the other hand, I do not use Active Python but rather the
> Python.org vanilla Python. I remembered that I have some
> challenges getting 64bit Python 2.7 to work with MinGW-w64.
>
> --
> Xiaofan
>
> --
> libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
> To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
>


libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx



-- 
Dr Joachim Schambach                 tel: +1 512 471 1303
The University of Texas at Austin    fax: +1 512 471 9637    
Department of Physics                email1: jschamba@xxxxxxxxxxxxxxxxxx
1 University Station C1600	     email2: jschamba@xxxxxxxxxxxxxxxxx
Austin, Texas 78712-0264, USA


libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx


Current Thread