为什么链接器在未在任何地方指定时寻找 python36_d.lib?
Why is the linker looking for python36_d.lib when not specified anywhere?
我正在使用 VS 2017 和 SWIG 编译 Python C++ extension module。
扩展模块(.pyd 文件)的链接器(用于调试配置)的命令是:
/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
这清楚地表明依赖于 python36.lib
而不是 python36_d.lib
。
尽管如此,链接器仍会抛出此错误:
LNK1104 : cannot open file 'python36_d.lib'
链接器不在链接器参数中时为什么要查找调试 LIB?
埋在 Python.h 包含的 headers 中的是这段代码:
# 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 */
如果定义了 _DEBUG
,pre-processor 选择 python36_d.lib
进行自动链接,即调试 MSVC 构建。
我正在使用 VS 2017 和 SWIG 编译 Python C++ extension module。
扩展模块(.pyd 文件)的链接器(用于调试配置)的命令是:
/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
这清楚地表明依赖于 python36.lib
而不是 python36_d.lib
。
尽管如此,链接器仍会抛出此错误:
LNK1104 : cannot open file 'python36_d.lib'
链接器不在链接器参数中时为什么要查找调试 LIB?
埋在 Python.h 包含的 headers 中的是这段代码:
# 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 */
如果定义了 _DEBUG
,pre-processor 选择 python36_d.lib
进行自动链接,即调试 MSVC 构建。