引自: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'".代码如下:

#include <stdio.h>
#include <Python.h> int main(void)
{
Py_Initialize();
if(!Py_IsInitialized()){
printf("Python Initialize failed.\n");
return ;
} PyRun_SimpleString("print('hello world!')");
Py_Finalize();
system("pause"); return ;
}

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 /* 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'的更多相关文章

  1. VS2008 LINK : fatal error LNK1104: cannot open file 'atls.lib'错误解决方案

    用VS 2008编写ATL的64位应用程序时,提示链接错误:VS2008 LINK : fatal error LNK1104: cannot open file 'atls.lib' 问题原因 VS ...

  2. LINK : fatal error LNK1104: cannot open file "mfc42d.lib"

    VC++6.0上建立了个基于MFC应用程序,在编译时候没出现错误,但在LINK的是时候出现这样的错误:Linking...LINK : fatal error LNK1104: cannot open ...

  3. 模板函数(template function)出现编译链接错误(link error)之解析

    总的结论:    将template function 或者 template class的完整定义直接放在.h文件中,然后加到要使用这些template function的.cpp文件中. 1. 现 ...

  4. 怎样处理“error C2220: warning treated as error - no object file generated”错误

    最近用VS2010 编译ceflib开源库是出现"怎样处理"error C2220: warning treated as error - no object file gener ...

  5. vs2010 创建预编译头 Debug 正常 Release Link Error问题解决

    问题:创建预编译头 Debug 正常 Release Link Error Main.obj : error LNK2005: ___@@_PchSym_@00@UmfilkilqUdrmzkkUki ...

  6. 创建预编译头 Debug 正常 Release Link Error:预编译头已存在,使用第一个 PCH

    创建预编译头 Debug 正常 Release Link Error Main.obj : error LNK2005: ___@@_PchSym_@00@UmfilkilqUdrmzkkUkilqU ...

  7. 编译boost程序出现如下错误fatal error LNK1104: cannot open file 'libboost_system-vc100-mt-gd-1_54.lib'的解决方法

    对于如下程序: #include <iostream> #include <boost/asio.hpp> #include <boost/date_time/posix ...

  8. Xcode编译报错:< Apple Mach-O Linker Warning > clang: error: no such file or directory: 'xxxx'

    Xcode编译报错概述: clang: error: no such file or directory: 'CoreGraphics' 一般原因是链接库内容导入丢失,这种的排查下target - B ...

  9. 安卓开发error opening trace file: No such file or directory (2)报错原因

    error opening trace file: No such file or directory (2) 这个问题的出现是因为运行的测试机android系统版本和项目api不一致导致. 改成一样 ...

随机推荐

  1. zookeeper 环境搭建

    1.准备三台服务器 ip分别为:192.168.100.128.192.168.100.129.192.168.100.133 a.修改主机名称 vi /etc/sysconfig/network 修 ...

  2. C# Ioc 接口注册实例以及注入MVC Controller

    当弄一个小程序时,就忽略了使用Ioc这种手段,作为一个帅气程序员,代码规范,你懂的~,废话不多说,快速搭建一个Ioc接口实例以及直接注入到 MVC Controller 构造函数中如下: MVC in ...

  3. RandomAccess接口的使用

    RandomAccess在类Collections的shuffle()方法中的使用:(jdk源码如下) /** * Randomly permute the specified list using ...

  4. BZOJ 3456: 城市规划 [多项式求逆元 组合数学 | 生成函数 多项式求ln]

    3456: 城市规划 题意:n个点组成的无向连通图个数 以前做过,今天复习一下 令\(f[n]\)为n个点的无向连通图个数 n个点的完全图个数为\(2^{\binom{n}{2}}\) 和Bell数的 ...

  5. CF 551E. GukiZ and GukiZiana [分块 二分]

    GukiZ and GukiZiana 题意: 区间加 给出$y$查询$a_i=a_j=y$的$j-i$最大值 一开始以为和论文CC题一样...然后发现他带修改并且是给定了值 这样就更简单了.... ...

  6. POJ 1222 EXTENDED LIGHTS OUT [高斯消元XOR]

    题意: $5*6$网格里有一些灯告诉你一开始开关状态,按一盏灯会改变它及其上下左右的状态,问最后全熄灭需要按那些灯,保证有解 经典问题 一盏灯最多会被按一次,并且有很明显的异或性质 一个灯作为一个方程 ...

  7. 怎么理解np.random.seed()?

    在使用numpy时,难免会用到随机数生成器.我一直对np.random.seed(),随机数种子搞不懂.很多博客也就粗略的说,利用随机数种子,每次生成的随机数相同. 我有两个疑惑:1, 利用随机数种子 ...

  8. IntelliJ IDEA下Maven SpringMVC+Mybatis入门搭建例子

    很久之前写了一篇SSH搭建例子,由于工作原因已经转到SpringMVC+Mybatis,就以之前SSH实现简单登陆的例子,总结看看SpringMVC+Mybatis怎么实现. Spring一开始是轻量 ...

  9. 配置Nginx代理服务器

    nginx另一个使用的比较多的情况是作为代理服务器,代理服务器接收请求,然后把请求传递到代理服务器,nginx最后会提取代理服务器的回复,并把这些回复发送给客户端.我们将配置一个基本的代理服务器,图片 ...

  10. Asp.net中Request.Url的各个属性对应的意义介绍

    Asp.net中Request.Url的各个属性对应的意义介绍 本文转载自 http://www.jb51.net/article/30254.htm 网络上关于Request.Url的说明已经很多也 ...