Question

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 are the library containing the third party methods we want to access.

  • cacint.h and cacint.c are 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), exposing the C code to Python.
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
  • I followed the Python extension tutorials for Windows from the python website.
  • I can successfully build the extension from Visual Studio 10.0 and make the extension run from a source code build of Python.
  • I am unable to make it work from the installed python (not the source code build) I copied the created .pyd file to the site-package folder and received an error when I tried to import the extension from the python console.
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top