最近研究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.

  1. // a.cpp
  2. #include <atlbase.h>
  1. // b.cpp
  2. #include <atlbase.h>
  3. int function()
  4. {
  5. return 0;
  6. }

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. DesignMode的状态处理

    自定义控件开发的调试及DesignMode的状态处理 在开发Winform程序的时候,我们往往需要根据需要做一些自定义的控件模块,这样可以给系统模块重复利用,或者实现更好的效果等功能.但在使用的时候, ...

  2. 玩转python之每次处理一个字符

    在Python中字符就是长度为1的字符串,所以可以循环遍历一个字符串,依次访问每一个字符,得到你想要的处理前提: 一个列表是个好主意,就像这样:thelist = list(thestring) 当然 ...

  3. MVC中验证码

    MVC中验证码的实现(经常用,记录备用)   一.目录 1.多层架构+MVC+EF+AUTOFAC+AUTOMAPPER: 2.MVC中验证码的实现(经常用,记录备用) 3.Ligerui首页的快速搭 ...

  4. c# 使用Codosys.dll(CDO)发送邮件

    准备工作: 从C:\Windows\System32将Codosys.dll拷到你的项目里,然后引用,或者直接引用Com组件也可以 然后看代码 ///<summary> /// 构造函数 ...

  5. 使用celery之怎么让celery跑起来

    celery 官网帮助文档  http://docs.celeryproject.org/en/latest/index.html 前言 自从发了上次的文章使用celery之深入celery配置, 有 ...

  6. Java 快速开发平台 WB 6.8 发布

    WebBuilder是一款开源的可视化Web应用开发和运行平台. 基于浏览器的集成开发环境,采用可视化的设计模式,支持控件的拖拽操作,能轻松完成前后台应用开发: 高效.稳定和可扩展的特点,适合复杂企业 ...

  7. Ubuntu环境搭建1

    Ubuntu环境搭建(一) 其实每次重装Ubuntu系统的时候都要进行一次基本到环境配置,而且每次总会忘记一些环境配置到东西,所以就写下这个博文,方便自己以后重装系统的时候回顾,同时也给大家做为重装系 ...

  8. 关闭Windows 2008下面应用程序出错后的提示

    写了一个服务器端程序,没有能处理所有的错误,总有一些错误会抛出到系统中去.于是写了一个进程守护者,一旦发现服务器端退出,可以在第一时间重新启动服务器,也算是一种折中的方案吧.理论上讲应该是可行的,但是 ...

  9. poj1872A Dicey Problem

    Home Problems Status Contest     284:28:39 307:00:00   Overview Problem Status Rank A B C D E F G H ...

  10. java基础知识拾遗(三)

    1.类加载 bootstrap classloader -引导(也称为原始)类加载器,它负责加载Java的核心类. extension classloader -扩展类加载器,它负责加载JRE的扩展目 ...