为什么链接器在任何地方都没有指定时寻找 python36_d.lib ? [英] Why is the linker looking for python36_d.lib when not specified anywhere?

查看:28
本文介绍了为什么链接器在任何地方都没有指定时寻找 python36_d.lib ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 VS 2017 和 SWIG 编译 Python C++ 扩展模块.

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

扩展模块(.pyd 文件)的链接器(用于调试配置)的命令是:

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 

这清楚地表明依赖是在 python36.lib 而不是 python36_d.lib.尽管如此,链接器仍会引发此错误:

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'

当调试 LIB 不在链接器参数中时,为什么链接器要寻找调试 LIB?

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

推荐答案

Python.h 包含的头文件中埋藏着这段代码:

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 */

如果定义了 _DEBUG,预处理器会自动选择 python36_d.lib 进行链接,即调试 MSVC 构建.

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

这篇关于为什么链接器在任何地方都没有指定时寻找 python36_d.lib ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆