Solution for link error:Cannot Open File 'python27_d.lib'
2013-01-17 18:32
495 查看
版权所有,转载请注明出处:http://guangboo.org/2013/01/17/solution-link-errorcannot-open-file-python27_dlib
使用C调用Python函数或解释器时,在添加了Include Directories和Library Directories等配置后,仍然编译错误:"LINK : fatal error LNK1104: cannot open file 'python27_d.lib'".代码如下:
Stackoverflow贴出了pyconfig.h头文件中对Python27_d.lib的引用(http://stackoverflow.com/questions/11311877/creating-a-dll-from-a-wrapped-cpp-file-with-
swig/14372472#14372472),该文件用于调试用,如下代码:
可以发现,只有MS_NO_COREDLL或Py_NO_ENABLE_SHARED被定义了,那么#ifdef MS_COREDLL块的代码就不会被编译。因此可以在Configuration Properties->C/C++->Preprocessor->Preprocessor Definitions添加MS_NO_COREDLL或Py_NO_ENABLE_SHARED,去掉_DEBUG,将没有效果。也可以在引用python.h头文件前添加#define MS_NO_COREDLL或#define Py_NO_ENABLE_SHARED。
使用C调用Python函数或解释器时,在添加了Include Directories和Library Directories等配置后,仍然编译错误:"LINK : fatal error LNK1104: cannot open file 'python27_d.lib'".代码如下:
#include <stdio.h> #include <Python.h> int main(void) { Py_Initialize(); if(!Py_IsInitialized()){ printf("Python Initialize failed.\n"); return 1; } PyRun_SimpleString("print('hello world!')"); Py_Finalize(); system("pause"); return 0; }
Stackoverflow贴出了pyconfig.h头文件中对Python27_d.lib的引用(http://stackoverflow.com/questions/11311877/creating-a-dll-from-a-wrapped-cpp-file-with-
swig/14372472#14372472),该文件用于调试用,如下代码:
/* For Windows the Python core is in a DLL by default. Test Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ #if !defined(MS_NO_COREDLL) && !defined(Py_NO_ENABLE_SHARED) # define Py_ENABLE_SHARED 1 /* standard symbol for shared library */ # define MS_COREDLL /* deprecated old symbol */ #endif /* !MS_NO_COREDLL && ... */ /* All windows compilers that use this header support __declspec */ #define HAVE_DECLSPEC_DLL /* For an MSVC DLL, we can nominate the .lib files used by extensions */ #ifdef MS_COREDLL # ifndef Py_BUILD_CORE /* not building the core - must be an ext */ # if defined(_MSC_VER) /* So MSVC users need not specify the .lib file in their Makefile (other compilers are generally taken care of by distutils.) */ # ifdef _DEBUG # pragma comment(lib,"python27_d.lib") # else # pragma comment(lib,"python27.lib") # endif /* _DEBUG */ # endif /* _MSC_VER */ # endif /* Py_BUILD_CORE */ #endif /* MS_COREDLL */
可以发现,只有MS_NO_COREDLL或Py_NO_ENABLE_SHARED被定义了,那么#ifdef MS_COREDLL块的代码就不会被编译。因此可以在Configuration Properties->C/C++->Preprocessor->Preprocessor Definitions添加MS_NO_COREDLL或Py_NO_ENABLE_SHARED,去掉_DEBUG,将没有效果。也可以在引用python.h头文件前添加#define MS_NO_COREDLL或#define Py_NO_ENABLE_SHARED。
相关文章推荐
- Solution for link error:Cannot Open File 'python27_d.lib'
- Solution for link error:Cannot Open File 'python27_d.lib'
- link error:Cannot Open File 'python27_d.lib'
- 如何解决VS2008调试时出现LINK : fatal error LNK1104: cannot open file 'LIBC.lib'
- LINK : fatal error LNK1104: cannot open file 'LIBCD.lib' 解决办法
- LINK : fatal error LNK1104: cannot open file 'LIBCD.lib'
- fatal error LNK1104: cannot open file 'msvcirtd.lib' 【solution】
- LINK 错误:LINK : fatal error LNK1104: cannot open file 'uafxwce.lib' 的解决办法
- LINK : fatal error LNK1104: cannot open file''**.lib'' 和 error LNK2001:
- VS2008编译错误—LINK : fatal error LNK1104: cannot open file 'LIBC.lib'
- VS2010调用python编写的代码error:cannot open file 'python27_d.lib'".
- LINK:fatal error LNK1104: cannot open file 'libc.lib'
- LINK : fatal error LNK1104: cannot open file "stlport_vc6_static.lib"
- LINK : fatal error LNK1104: cannot open file 'xxx.exe'
- error LNK1104: cannot open file 'Spromeps_Win64.lib'
- VS2005:cannot open file 'LIBC.lib'
- 类重定义问题。。。。BSCMAKE: error BK1506 : cannot open file '.\Debug\。。。。
- python: error while loading shared libraries: libpython3.4m.so.1.0: cannot open shared object file:
- 解决error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No su
- LINK : fatal error LNK: cannot open file "uafxcw.lib"的解决方法