关于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中选中工程文件. ...
随机推荐
- NUnit单元测试资料汇总
NUnit单元测试资料汇总 从安装到配置 首先到官网http://www.nunit.org/下载如下图的资料,安装NUnit-2.6.1.msi包. 然后挂在VS2010外部工具这个地方来使用,工具 ...
- Dynamics CRM 客户端的插件调试
Dynamics CRM 客户端的插件调试 一直以来,Dynamics CRM插件在大家的印象中都是不便于调试的,根据官方文档(http://technet.microsoft.com/zh-cn/l ...
- c#二进制、十进制、16进制之间的转换
//十进制转二进制 Console.WriteLine(Convert.ToString(69, 2)); //十进制转八进制 Console.WriteLine(Convert.ToString(6 ...
- AHOI1997彩旗飘飘 VIJOS1097合并果子(noip2007)
AHOI彩旗飘飘 这是一题类似于排列组合的题目吧...递推状态 数组f[100][100][100][2];表示红旗数目,黄旗数目,颜色改变的次数,末尾的旗的颜色(0为黄,1为红) 之后就是如何写递推 ...
- [转]Hooked on DTrace
source link: 1.http://blog.bignerdranch.com/1907-hooked-on-dtrace-part-1/ 2.http://blog.bignerdranch ...
- 新部署的linux web服务器error Host ‘*.*.*.*’ is not allowed to connect to this MySQL server
最近上头交给我个任务,把WINDOWS平台下开发的网站,部署在LINUX环境上. 把mysql安装好了,所有表单都导入没问题,然后代码都放在tomcat下的webapps文件夹下了,主页 面可以正常显 ...
- asp.net mvc框架的一些切入点
IhttpModule+配置文件,对请求进行进一步的整理.过滤与转发: global文件中以Application_xx的保护方法进行切入的方式,此方法等同于IHttpModule方法.IHttpMo ...
- 关于socket通讯,如何才能高效?
关于socket通讯,如何才能高效? 网络通讯,一个不朽的话题,今天和一个做游戏的朋友(以前的同事聊天),他向我诉说了他的痛苦 他之前是做客户端的,无奈人力资源紧张,也开始搞服务器,他说自己的服务器总 ...
- WPF刷新界面之坎坷路
WPF刷新界面之坎坷路 项目需要一个硬件检测功能,需要用到界面刷新,刚开始想用个定时器,对检测过的硬设定时添加后刷新界面. 但是很遗憾,定时器并不能进行刷新.后台检测List数据里面已经添加了很多了很 ...
- [置顶] vs2008 编译adb 支持4.2 android 系统(改进版)
QQ: 2506314894 本想晚些时候放出来的,但是按捺不住啊,所以修改了之后就立即放出来了.先说明一下,这次用的adb 的源码比较新的,用的vs2008 编译出来,只有一个exe 文件,直接就可 ...
