关于VS2010编译警告LNK4221
最近研究duilib,准备把里面自定义的一些工具类如CDuiString什么的用ATL的替换掉,于是遇到久仰大名的



Linker Tools Warning LNK4221
Visual Studio 2015
This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
Consider the following two code snippets.
// a.cpp
#include <atlbase.h>
// b.cpp
#include <atlbase.h>
int function()
{
return 0;
}
To compile the files and create two object files, run cl /c a.cpp b.cpp at a command prompt. If you link the object files by running link /lib /out:test.lib a.obj b.obj, you will receive the LNK4221 warning. If you link the objects by running link /lib /out:test.lib b.obj a.obj, you will not receive a warning.
No warning is issued in the second scenario because the linker operates in a last-in first-out (LIFO) manner. In the first scenario, b.obj is processed before a.obj, and a.obj has no new symbols to add. By instructing the linker to process a.obj first, you can avoid the warning.
A common cause of this error is when two source files specify the option /Yc (Create Precompiled Header File) with the same header file name specified in the Precompiled Header field. A common cause of this problem deals with stdafx.h since, by default, stdafx.cpp includes stdafx.h and does not add any new symbols. If another source file includes stdafx.h with /Yc and the associated .obj file is processed before stdafx.obj, the linker will throw LNK4221.
One way to resolve this problem is to make sure that for each precompiled header, there is only one source file that includes it with/Yc. All other source files must use precompiled headers. For more information about how to change this setting, see /Yu (Use Precompiled Header File).
意思是除了 stdafx.cpp 外,其它包含了 stdafx.h 的源文件如果预编译项选择了 /Yc 就会出现这个警告。
我们知道一个项目中一般只将 stdafx.cpp 的预编译头文件选项设置为 /Yc 其他源文件如果要使用预编译头文件则设为 /Yu 。
于是查看 XUnzip.cpp 的预编译头文件选项
发现是空白的,那么把它设为 /Yu,然后改回 #include "stdafx.h".
OK ALL DONE!
This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
Consider the following two code snippets.
// a.cpp
#include <atlbase.h>
// b.cpp
#include <atlbase.h>
int function()
{
return 0;
}
To compile the files and create two object files, run cl /c a.cpp b.cpp at a command prompt. If you link the object files by running link /lib /out:test.lib a.obj b.obj, you will receive the LNK4221 warning. If you link the objects by running link /lib /out:test.lib b.obj a.obj, you will not receive a warning.
No warning is issued in the second scenario because the linker operates in a last-in first-out (LIFO) manner. In the first scenario, b.obj is processed before a.obj, and a.obj has no new symbols to add. By instructing the linker to process a.obj first, you can avoid the warning.
A common cause of this error is when two source files specify the option /Yc (Create Precompiled Header File) with the same header file name specified in the Precompiled Header field. A common cause of this problem deals with stdafx.h since, by default, stdafx.cpp includes stdafx.h and does not add any new symbols. If another source file includes stdafx.h with /Yc and the associated .obj file is processed before stdafx.obj, the linker will throw LNK4221.
One way to resolve this problem is to make sure that for each precompiled header, there is only one source file that includes it with/Yc. All other source files must use precompiled headers. For more information about how to change this setting, see /Yu (Use Precompiled Header File).
关于VS2010编译警告LNK4221的更多相关文章
- VS2010 win7 QT4.8.0,实现VS2010编译调试Qt程序,QtCreator静态发布程序
下载源代码,注意一定是源码压缩包如qt-everywhere-opensource-src-4.8.0.zip, 不是Qt发布的已编译的不同版本的标准库如qt-win-opensource-4.8.0 ...
- 亲测VS2010纯静态编译QT4.8.0,实现VS2010编译调试Qt程序,QtCreator静态发布程序(图文并茂,非常详细)
下载源代码,注意一定是源码压缩包如qt-everywhere-opensource-src-4.8.0.zip,不是Qt发布的已编译的不同版本的标准库如qt-win-opensource-4.8.0- ...
- VS2010编译Boost 1.57 静态链接库
http://www.cnblogs.com/cuish/p/4175491.html 0.前提 Boost库版本 1.57.0 下载地址 http://www.boost.org/users/his ...
- App开发流程之使用分类(Category)和忽略编译警告(Warning)
Category使得开发过程中,减少了继承的使用,避免子类层级的膨胀.合理使用,可以在不侵入原类代码的基础上,写出漂亮的扩展内容.我更习惯称之为"分类". Category和Ext ...
- 【读书笔记】iOS-忽略编译警告
一,忽略编译警告的命令. -w 禁止掉所有的编译警告. -Wno-unused-variable 只禁止掉未使用的变量的编译警告. 二,忽略编译警告的方法. targets--->Buil ...
- vs2010 编译Qt5.2 rc1
首先要准备一些依赖: 下载Qt 5.2.0 rc版的源码 qt-everywhere-opensource-src-5.2.0-rc1.7z 并解压出来, 我的路径为D:\qt5\qt-src-5.2 ...
- GCC编译警告和错误
1 error: expected expression before 'else' else之前无表达式. 2 error: lvalue required as left operand of a ...
- 使用vs2010编译 Python \ SIP \ PyQt4
(1)先使用vs2010编译 Python http://www.cnblogs.com/fortwo/archive/2013/04/16/3023871.html 注意,若编译的为debug版的P ...
- 在Xcode中如何屏蔽某个源文件的编译警告信息
某些时候如果我们的源码在编译过程中出现大量的编译警告时,看起来是挺不爽的:但又确实没办法解决警告问题的时候,我们可以使用下面的方法来屏蔽指定的某个文件的所有警告信息. 1.在Xcode中选中工程文件. ...
随机推荐
- c#事件求解
闲来无聊对于clr一书又重新温习了下,但是看到事件这张后还是有很多的困惑,对于事件能力CLR是这样描述,通知其它对象发生特定的事情. 1.其它对象:是指对于事件的关注者 2.特定的事件:对于满足事件交 ...
- 一个ASP.NET Web API 2.0应用
在一个空ASP.NET Web项目上创建一个ASP.NET Web API 2.0应用 由于ASP.NET Web API具有与ASP.NET MVC类似的编程方式,再加上目前市面上专门介绍ASP.N ...
- Content Negotiation(内容协商)
Asp.Net Web API 2第十四课——Content Negotiation(内容协商) 前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http:// ...
- Oracle 补丁及opatch 工具介绍
一. CPU(Critical Patch Update) 一个CPU内包含了对多个安全漏洞的修复,并且也包括相应必需的非安全漏洞的补丁.CPU是累积型的,只要安装最新发布的CPU即可,其中包括之前发 ...
- A Free , Fast and Small Automatic Formatter for C , C++ , C# , Java Source Codes
A Free , Fast and Small Automatic Formatterfor C , C++ , C# , Java Source Codes Indenting source cod ...
- Mac OS X安装之硬盘和光盘引导总结
继上一篇虚拟机环境下的安装,这篇文档主要描述硬盘和光盘引导安装Mac OS X,并可实现多操作系统. 硬盘安装: 首先介绍下硬盘安装需要用到的软件. Java虚拟机.作为HFSExplorer的运行前 ...
- Asp.Net Web API 2(CRUD操作)第二课
Asp.Net Web API 2(CRUD操作)第二课 Asp.Net Web API 导航 Asp.Net Web API第一课:入门http://www.cnblogs.com/aehyok ...
- last error : SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate veri
今天在用搜狐提供的邮件群发系统的sdk,做发送邮件的测试时,提示: last error : SSL certificate problem, verify that the CA cert is O ...
- Stream使用教程
现在,计算机CPU运行速度的快速发展已经远远超过了内存的访问速度.越来越多的程序性能被内存带宽所限制,而不是计算机的CPU运行速率. Stream benchmark是一个简单的合成基准测试程序,衡量 ...
- DOS头分析
DOS头分析 PE文件结构综览: 首先上图片: 看到上面的图片可以清晰的看到PE结构复杂结构式什么样子的.有DOS首部,PE头部,PE节表,很多的表块,最后就是一些调试信息. DOS头由DOS 'MZ ...
