2

I am compiling a Python C++ extension module using VS 2017 and SWIG.

The command to the linker (for Debug configuration) for the extension module (a .pyd file) is :

/OUT:"D:\TFS\Dev\CGALSwig\cgal-swig-binding-4.x\build\build-python\CGAL\_CGAL_Kernel.pyd" /MANIFEST /NXCOMPAT /PDB:"D:/TFS/Dev/CGALSwig/cgal-swig-binding-4.x/build/build-python/CGAL/_CGAL_Kernel.pdb" /DYNAMICBASE "C:\Users\helloworld\AppData\Roaming\python\libs\python36.lib" "Debug\CGAL_Kernel_cpp.lib" "D:\TFS\Dev\CGALSwig\mpfr\lib\libmpfr-4.lib" "D:\TFS\Dev\CGALSwig\gmp\lib\libgmp-10.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib" /IMPLIB:"D:/TFS/Dev/CGALSwig/cgal-swig-binding-4.x/build/build-python/CGAL/Debug/CGAL_Kernel.lib" /DEBUG /DLL /MACHINE:X64 /INCREMENTAL /PGD:"D:\TFS\Dev\CGALSwig\cgal-swig-binding-4.x\build\build-python\CGAL\_CGAL_Kernel.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"_CGAL_Kernel_python.dir\Debug\_CGAL_Kernel.pyd.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"D:/TFS/Dev/CGALSwig/cgal-swig-binding-4.x/build/build-python/CGAL" /LIBPATH:"D:/TFS/Dev/CGALSwig/cgal-swig-binding-4.x/build/build-python/CGAL/Debug" /TLBID:1 

This clearly states that the dependency is on python36.lib and not python36_d.lib. Still, the linker throws this error :

LNK1104 : cannot open file 'python36_d.lib'

Why is the linker looking for debug LIB when it is not in the linker arguments ?

johngreen
  • 2,676
  • 5
  • 32
  • 47

1 Answers1

6

Buried in the headers included by Python.h is this code:

#           if defined(_DEBUG)
#               pragma comment(lib,"python36_d.lib")
#           elif defined(Py_LIMITED_API)
#               pragma comment(lib,"python3.lib")
#           else
#               pragma comment(lib,"python36.lib")
#           endif /* _DEBUG */

The pre-processor selects python36_d.lib for linking automatically if _DEBUG is defined, i.e. a debug MSVC build.

Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251