Struggling to create an extension wrapping a 3rd party dll

Christoff Kok christoff.kok at ex-mente.co.za
Tue Mar 11 01:51:14 EDT 2014


On Wednesday, 5 March 2014 09:10:33 UTC+2, Christoff Kok  wrote:
> Hi,
> 
> 
> 
> We are trying to wrap a 3rd party dll (written in C) to access it through python.
> 
> The dll has a .lib .c and a .h file with it. We are accessing the dll through the .c file.
> 
> 
> 
> Outisde of the extension (running as a console application), the code works without an issue. without the 3rd party dll, the python extension works without an issue. The issue comes in when trying combine the third party dll with the python extension.
> 
> 
> 
> Here is the distutil installation script
> 
> 
> 
> ################ Setup.py ################################
> 
> 
> 
> from distutils.core import setup, Extension
> 
> 
> 
> chemAppPython_mod = Extension('chemAppPython', sources = ['chemAppPython.c', 'cacint.c'], libraries=['ca_vc_opt_e'], depends = ['cacint.h'])
> 
> 
> 
> setup(name = "chemAppPython",
> 
>     version = "1.0",
> 
>     description = "The ChemnApp Python module",
> 
>     ext_modules = [chemAppPython_mod],
> 
> 	data_files = [('',['ca_vc_e.dll'])]
> 
> )
> 
> 
> 
> ##########################################################
> 
> 
> 
> * ca_vc_opt_e.lib and ca_vc_e.dll is the library containing the third party methods we want to access.
> 
> 
> 
> * cacint.h and cacint.c is the files acting as an interface to the ca_vc_opt_e.lib and ca_vc_e.dll.
> 
> * chemAppPython.c is file containing the code wrapping the calls to the cacint.c (and in effect, the third party dll)
> 
> 
> 
> The errors we are receiving are:
> 
> C:\Python33\source\Python-3.3.4\ChemAppPython>setup.py install
> 
> running install
> 
> running build
> 
> running build_ext
> 
> building 'chemAppPython' extension
> 
> creating build
> 
> creating build\temp.win-amd64-3.3
> 
> creating build\temp.win-amd64-3.3\Release
> 
> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python33\include -IC:\Python33\include /TcchemAppPython.c /Fobuild\temp.win-amd64-3.3\Release\chemAppPython.obj
> 
> chemAppPython.c
> 
> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python33\include -IC:\Python33\include /Tccacint.c /Fobuild\temp.win-amd64-3.3\Release\cacint.obj
> 
> cacint.c
> 
> cacint.c(357) : warning C4267: 'function' : conversion from 'size_t' to 'long', possible loss of data
> 
> cacint.c(390) : warning C4267: 'function' : conversion from 'size_t' to 'long', possible loss of data
> 
> .
> 
> .
> 
> . (some more of the same warning message for different functions.)
> 
> .
> 
> cacint.c(619) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
> 
> .
> 
> .
> 
> . 
> 
> . (some more of the same warning message at different positions in code.)
> 
> .
> 
> creating build\lib.win-amd64-3.3
> 
> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python33\libs /LIBPATH:C:\Python33\PCbuild\amd64 ca_vc_opt_e.lib /EXPORT:PyInit_chemAppPython build\temp.win-amd64-3.3\Release\chemAppPython.obj build\temp.win-amd64-3.3\Rele
> 
> chemAppPython.obj : warning LNK4197: export 'PyInit_chemAppPython' specified multiple times; using first specification
> 
>    Creating library build\temp.win-amd64-3.3\Release\chemAppPython.lib and object build\temp.win-amd64-3.3\Release\chemAppPython.exp
> 
> cacint.obj : error LNK2019: unresolved external symbol TQINI referenced in function tqini
> 
> cacint.obj : error LNK2019: unresolved external symbol TQOPEN referenced in function tqopen
> 
> .
> 
> .
> 
> . (a lot more of them, for different methods. Again, it builds and runs fine in the console app host application.)
> 
> .
> 
> build\lib.win-amd64-3.3\chemAppPython.pyd : fatal error LNK1120: 74 unresolved externals
> 
> error: command '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe"' failed with exit status 1120
> 
> 
> 
> 
> 
> Help would really be appreciated.

I solved it. Apparently 64bit Python doesn't mingle well (or at all) with 32bit dll's. I downgraded python to a 32bit version and everything just worked.



More information about the Python-list mailing list