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

warning C4251: xxx  needs to have dll-interface to be used by clients of class xxx
这个其实很久前就遇到过,当时做法是改用该类型的指针,现在不想这么做了,既然dll中导出类成员变量不合适,那就将duilib作为静态库使用吧。进行如下设置
 
 Debug下编译木有问题,当换成Release后
出现如下错误
 
 文件目录中确实这两个文件不在同一级目录,好吧,改成 #include "../stdafx.h" 试试,然而这次主角登场了
 从msdn搜索到是这么说的

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!

关于VS2010编译警告LNK4221的更多相关文章

  1. VS2010 win7 QT4.8.0,实现VS2010编译调试Qt程序,QtCreator静态发布程序

    下载源代码,注意一定是源码压缩包如qt-everywhere-opensource-src-4.8.0.zip, 不是Qt发布的已编译的不同版本的标准库如qt-win-opensource-4.8.0 ...

  2. 亲测VS2010纯静态编译QT4.8.0,实现VS2010编译调试Qt程序,QtCreator静态发布程序(图文并茂,非常详细)

    下载源代码,注意一定是源码压缩包如qt-everywhere-opensource-src-4.8.0.zip,不是Qt发布的已编译的不同版本的标准库如qt-win-opensource-4.8.0- ...

  3. VS2010编译Boost 1.57 静态链接库

    http://www.cnblogs.com/cuish/p/4175491.html 0.前提 Boost库版本 1.57.0 下载地址 http://www.boost.org/users/his ...

  4. App开发流程之使用分类(Category)和忽略编译警告(Warning)

    Category使得开发过程中,减少了继承的使用,避免子类层级的膨胀.合理使用,可以在不侵入原类代码的基础上,写出漂亮的扩展内容.我更习惯称之为"分类". Category和Ext ...

  5. 【读书笔记】iOS-忽略编译警告

    一,忽略编译警告的命令. -w   禁止掉所有的编译警告. -Wno-unused-variable  只禁止掉未使用的变量的编译警告. 二,忽略编译警告的方法. targets--->Buil ...

  6. vs2010 编译Qt5.2 rc1

    首先要准备一些依赖: 下载Qt 5.2.0 rc版的源码 qt-everywhere-opensource-src-5.2.0-rc1.7z 并解压出来, 我的路径为D:\qt5\qt-src-5.2 ...

  7. GCC编译警告和错误

    1 error: expected expression before 'else' else之前无表达式. 2 error: lvalue required as left operand of a ...

  8. 使用vs2010编译 Python \ SIP \ PyQt4

    (1)先使用vs2010编译 Python http://www.cnblogs.com/fortwo/archive/2013/04/16/3023871.html 注意,若编译的为debug版的P ...

  9. 在Xcode中如何屏蔽某个源文件的编译警告信息

    某些时候如果我们的源码在编译过程中出现大量的编译警告时,看起来是挺不爽的:但又确实没办法解决警告问题的时候,我们可以使用下面的方法来屏蔽指定的某个文件的所有警告信息. 1.在Xcode中选中工程文件. ...

随机推荐

  1. Julia语言:让高性能科学计算人人可用

    Julia语言:让高性能科学计算人人可用要:一群科学家对现有计算工具感到不满:他们想要一套开源系统,有C的快速,Ruby的动态,Python的通用,R般在统计分析上得心应手,Perl的处理字符串处理, ...

  2. 加载DLL模块

    关于Windows平台下应用程序加载DLL模块的问题. 本文将讨论以下问题: (1)Windows可执行程序会从哪些目录下加载DLL. (2)如何将可执行使用的DLL放置到统一的目录下,而不是与EXE ...

  3. 统计重1到n的正整数中1的个数

    问题: 给定一个十进制正整数N,写下从1开始,到N的所有整数,然后数一下其中出现的所有“1”的个数. 例如:N= 2,写下1,2.这样只出现了1个“1”. N= 12,我们会写下1, 2, 3, 4, ...

  4. 通过DialogFragment从DatePicker或TimePicker中获取日期数据

    通过DialogFragment从DatePicker或TimePicker中获取日期数据 一个activity类,里面存有date和time的变量,想通过dialogfragment的方式获取用户输 ...

  5. cocos2d学习之路四(添加遥控杆)

    添加遥控杆 1. 首先需要再HelloWorldLayer.h中包含ZJoystick.h文件 并且让其实现ZJoystickDelegate协议 2.打开HelloWorldLayer.mm文件实现 ...

  6. JavaEE:XML解析

    XML解析技术概述1.XML 技术主要企业应用1)存储和传输数据 2)作为框架的配置文件2.使用xml 存储和传输数据涉及到以下两点1)通过程序生成xml2)读取xml 中数据 ---- xml 解析 ...

  7. [置顶] Oracle学习路线与方法

    还没有整理好.... 1.学习路线 Oracle官方文档:2 Day DBA-->2 Day+Performance Tuning Guide--->Administrator's Gui ...

  8. JAVA-读取文件部分内容计算HASH值

    对于一些大文件,有时会需要计算部分内容的Hash,下面的函数计算了 文件头尾各1M,中间跳跃100M取10K 以及文件大小的Hash值 public static String CalHash(Str ...

  9. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第四章:更高级的数据管理

    在这一章我们将学习如何正确地删除分类信息,如何向数据库填充种子数据,如何使用Code First Migrations基于代码更改来更新数据库,然后学习如何执行带有自定义错误消息的验证. 注意:如果你 ...

  10. windows下使用命令查看端口占用情况

    使用下面的命令查看端口占用情况: 比如查看3000端口的占用情况 netstat -ano|findstr 3000 运行后,结果如下: 可以看到进程号为9692的占用了该端口,使用下面的命令查看是哪 ...