I'm having issues linking the atl
library in my cython project.
I currently have Visual C++ 9.0 and Visual Studio 2008 installed with the SP1 and Visual Studio 2015.
My build is successful with python 3.5 using VS2015 when I link the libraries using a full path. In python 2.7 linked to Visual C++ 9.0, the header is found but the library cannot be linked.
I know that the lib has been moved to the .h
file in the new versions so it may be hard to reproduce.
I'm using this setup.py
:
# Cython compile instructions
from Cython.Build import cythonize
try:
from setuptools import setup
from setuptools import Extension
except ImportError:
print("using distutils")
from distutils.core import setup
from distutils.extension import Extension
# Use python setup.py build_ext --inplace
# to compile
vs27 = ['C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\atlmfc\\lib',
'C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\atlmfc\\include',
'C:\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\atlmfc\\src\\atl\\atls',
]
vs35 = ['C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\atlmfc\\include',
'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\atlmfc\\lib',
'C:\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\atlmfc\\src\\atl\\atls',]
extensions = [Extension("access", ["access.pyx"], include_dirs=vs27)]
setup(
name = "access",
ext_modules = cythonize(extensions),
include_dirs = vs27,
)
When I compile using python 2.7 and Visual C++ 9.0 I get:
running build_ext
building 'access' extension
C:\Users\tboquet.R2000\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\\Program -IFiles -I(x86)\\Microsoft -IVisual -IStudio -I9.0\\VC\\atlmfc\\lib "-IC:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\include" "-IC:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\lib" "-IC:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\src\atl\atls" "-IC:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\include" "-IC:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\lib" "-IC:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\src\atl\atls" -IC:\Anaconda3\envs\anapy27\include -IC:\Anaconda3\envs\anapy27\PC /Tpaccess.cpp /Fobuild\temp.win-amd64-2.7\Release\access.obj
access.cpp
C:\Users\tboquet.R2000\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\xlocale(342) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
C:\Users\tboquet.R2000\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\\Program -IFiles -I(x86)\\Microsoft -IVisual -IStudio -I9.0\\VC\\atlmfc\\lib "-IC:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\include" "-IC:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\lib" "-IC:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\src\atl\atls" "-IC:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\include" "-IC:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\lib" "-IC:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\src\atl\atls" -IC:\Anaconda3\envs\anapy27\include -IC:\Anaconda3\envs\anapy27\PC /Tpdbaccessor.cpp /Fobuild\temp.win-amd64-2.7\Release\dbaccessor.obj
dbaccessor.cpp
C:\Users\tboquet.R2000\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\xlocale(342) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
dbaccessor.cpp(111) : warning C4267: 'argument' : conversion from 'size_t' to 'UINT', possible loss of data
c:\users\tboquet.r2000\documents\visual studio 2013\projects\accessor\accessor\dbaccessor.cpp(220) : warning C4715: 'dbaccessor::connect' : not all control paths return a value
C:\Users\tboquet.R2000\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Anaconda3\envs\anapy27\libs /LIBPATH:C:\Anaconda3\envs\anapy27\PCbuild\amd64 /EXPORT:initaccess build\temp.win-amd64-2.7\Release\access.obj build\temp.win-amd64-2.7\Release\dbaccessor.obj /OUT:build\lib.win-amd64-2.7\access.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\access.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\access.pyd.manifest
LINK : fatal error LNK1104: cannot open file 'atls.lib'
error: command 'C:\\Users\\tboquet.R2000\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\link.exe' failed with exit status 1104
Do I have to use another way of linking the libraries or is there any workaround regarding this error?
I was able to resolve the issue but not in the most elegant way. The problem is that the linker does not have access to the library because not /LIBPATH
where it can find it is declared.
It's possible to copy the library in one of the /LIBPATH
used by linker.exe
. I put it in C:\Anaconda3\envs\anapy27\libs
and I was able to compile the package and load the .pyd
.
A better way of solving the issue would be to instruct setuptools to consider it (adding the right /LIBPATH
in the last command like in the previous commands). I'm not sure if it's a bug in setuptools or if an argument exists for that.
If someone has a better answer to this please comment on this one and I will update it!