Cython: LINK : fatal error LNK1104: cannot open file 'atls.lib'

Question:

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:Userstboquet.R2000AppDataLocalProgramsCommonMicrosoftVisual C++ for Python9.0VCBinamd64cl.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.0VCatlmfcinclude" "-IC:Program Files (x86)Microsoft Visual Studio 9.0VCatlmfclib" "-IC:Program Files (x86)Microsoft Visual Studio 9.0VCatlmfcsrcatlatls" "-IC:Program Files (x86)Microsoft Visual Studio 9.0VCatlmfcinclude" "-IC:Program Files (x86)Microsoft Visual Studio 9.0VCatlmfclib" "-IC:Program Files (x86)Microsoft Visual Studio 9.0VCatlmfcsrcatlatls" -IC:Anaconda3envsanapy27include -IC:Anaconda3envsanapy27PC /Tpaccess.cpp /Fobuildtemp.win-amd64-2.7Releaseaccess.obj
access.cpp
C:Userstboquet.R2000AppDataLocalProgramsCommonMicrosoftVisual C++ for Python9.0VCIncludexlocale(342) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
C:Userstboquet.R2000AppDataLocalProgramsCommonMicrosoftVisual C++ for Python9.0VCBinamd64cl.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.0VCatlmfcinclude" "-IC:Program Files (x86)Microsoft Visual Studio 9.0VCatlmfclib" "-IC:Program Files (x86)Microsoft Visual Studio 9.0VCatlmfcsrcatlatls" "-IC:Program Files (x86)Microsoft Visual Studio 9.0VCatlmfcinclude" "-IC:Program Files (x86)Microsoft Visual Studio 9.0VCatlmfclib" "-IC:Program Files (x86)Microsoft Visual Studio 9.0VCatlmfcsrcatlatls" -IC:Anaconda3envsanapy27include -IC:Anaconda3envsanapy27PC /Tpdbaccessor.cpp /Fobuildtemp.win-amd64-2.7Releasedbaccessor.obj
dbaccessor.cpp
C:Userstboquet.R2000AppDataLocalProgramsCommonMicrosoftVisual C++ for Python9.0VCIncludexlocale(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:userstboquet.r2000documentsvisual studio 2013projectsaccessoraccessordbaccessor.cpp(220) : warning C4715: 'dbaccessor::connect' : not all control paths return a value
C:Userstboquet.R2000AppDataLocalProgramsCommonMicrosoftVisual C++ for Python9.0VCBinamd64link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:Anaconda3envsanapy27libs /LIBPATH:C:Anaconda3envsanapy27PCbuildamd64 /EXPORT:initaccess buildtemp.win-amd64-2.7Releaseaccess.obj buildtemp.win-amd64-2.7Releasedbaccessor.obj /OUT:buildlib.win-amd64-2.7access.pyd /IMPLIB:buildtemp.win-amd64-2.7Releaseaccess.lib /MANIFESTFILE:buildtemp.win-amd64-2.7Releaseaccess.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?

Asked By: Thomas W. Boquet

||

Answers:

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:Anaconda3envsanapy27libs 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!

Answered By: Thomas W. Boquet

you can have something like this…

extensions = [Extension("access", ["access.pyx"], include_dirs=vs27),libraries=["d:\cpp\T\x64\Release\TemplateNestDll\atls"])]
Answered By: Aftershock
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.