关于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中选中工程文件. ...
随机推荐
- [转载]John Burkardt搜集的FORTRAN源代码
Over the years, I have collected, modified, adapted, adopted or created a number of software package ...
- C#简单实现贪吃蛇程序(LinQ + Entity)
做梦想起来的C#简单实现贪吃蛇程序(LinQ + Entity) 最近一直在忙着单位核心开发组件的版本更新,前天加了一个通宵,昨天晚上却睡不着,脑子里面突然不知怎的一直在想贪吃蛇的实现方法.以往也有类 ...
- LInux 2.6 编译内核出现Question
问:在make menuconfig配置完之后(选的默认配置),然后就make出现如下错误:root@org:/usr/src/linux-2.6.32.27# make CHK include/li ...
- 使用指定格式的字符串变量格式化日期字符串,DateAndTime取时间间隔
private void btn_GetTime_Click(object sender, EventArgs e) { lab_time.Text = DateTime.Now.ToString(& ...
- C# STA和MTA线程设置
参考资料: http://www.yesky.com/20010207/158097.shtml http://www.ftponline.com/china/XmlFile.aspx?ID=242 ...
- iOS基础 - 手势识别 与 手势说明
一.使用手势识别的四个步骤 1> 实例化手势识别 - (id)initWithTarget:(id)target action:(SEL)action; 2> 设置手势识别属性 3> ...
- AHOI1997彩旗飘飘 VIJOS1097合并果子(noip2007)
AHOI彩旗飘飘 这是一题类似于排列组合的题目吧...递推状态 数组f[100][100][100][2];表示红旗数目,黄旗数目,颜色改变的次数,末尾的旗的颜色(0为黄,1为红) 之后就是如何写递推 ...
- 【C#】聊聊不需要记密码的密码管理
密码管理(Password Management)肯定所有人都不会陌生,密码管理的来源也是来自于实际需求,当人们需要使用到密码的场景越来越多,场景也越来越复杂,密码的记录就成为了“难题”和“负担”,很 ...
- HTML + Javascript开发AIR应用
HTML + Javascript开发AIR应用 目录 背景什么是AIR?环境准备运行效果开发过程目录结构应用程序描述符HTML页面调试备注 背景返回目录 断断续续用Winform和WPF开发过一些小 ...
- JavaScript面向对象编程(一)原型与继承
原型(prototype) JavaScript是通过原型(prototype)进行对象之间的继承.当一个对象A继承自另外一个对象B后,A就拥有了B中定义的属性,而B就成为了A的原型.JavaScri ...
