服务器 python cant open file_Solution for link error:Cannot Open File 'python27_d.lib'

感谢原作者

使用C调用Python函数或解释器时,在添加了Include Directories和Library Directories等配置后,仍然编译错误:"LINK : fatal error LNK1104: cannot open file 'python27_d.lib'".代码如下:

#include #include

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;

}

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_SHARED1 /*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*/#ifdefined(_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。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值