引自: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. 【mac】mac os X更新High Sierra后出现的问题

    今天更新了一下macbook pro的系统到10.13.1版本,出现了几个小问题,总结一下解决方案: git客户端无法使用 解决方案如下: http://blog.csdn.net/kedongjun ...

  2. python字符串常用内置方法

    python字符串常用内置方法 定义: 字符串是一个有序的字符的集合,用与存储和表示基本的文本信息. python中引号中间包含的就是字符串. # s1='hello world' # s2=&quo ...

  3. bzoj 3597: [Scoi2014]方伯伯运椰子 [01分数规划 消圈定理 spfa负环]

    3597: [Scoi2014]方伯伯运椰子 题意: from mhy12345 给你一个满流网络,对于每一条边,压缩容量1 需要费用ai,扩展容量1 需要bi, 当前容量上限ci,每单位通过该边花费 ...

  4. js跨域解决方案

    1.参考该文档:http://blog.csdn.net/enter89/article/details/51205752 2. 参考网络:http://www.ruanyifeng.com/blog ...

  5. hbuilder ios 打包失败,无法导入p12证书的解决方案

    问题描述: 在profile文件和私钥证书通过hbuilder ios 打包成功过的前提下,突然遇到打包失败的问题,问题详情是无法导入p12证书. 探索过程: 本着遇到问题先自省的态度,重复打包了几次 ...

  6. redis新手入门,摸不着头脑可以看看<一>

    公司在用redis,但我并不会.所以需求就来了.. redis的好处坏处自己百度就好我也不去复制黏贴了. ----------------------------------------------- ...

  7. 关于Apache配置虚拟主机后在局域网中让其他电脑访问

    #-----------adxssp------------# NameVirtualHost *:80 <VirtualHost *:80> ServerName www.b.com D ...

  8. SQL SERVER FOR LINUX初体验

    今天得空,就在Ubuntu17.04上安装了SQL SERVER 2017体验下,总体来说还是不错的. 在Ubuntu上安装SQL SERVER 2017还是比较方便的,只需几条命令即可: curl ...

  9. 读书简记-java与模式

  10. url路径去掉两个opencms

    采用刚刚的方法安装OpenCMS之后,站点url中会存在两个opencms,造成访问url路径过长,下面讲解一种去掉两个opencms的方法. 1.去掉第一个opencms 安装时采用ROOT安装,即 ...