如何消除Larning LNK4221? [英] How to eliminate Warning LNK4221?
问题描述
我正在使用c ++/windows窗体(Visual Studio 2010)开发一个项目,我们有4个项目:
I am working on a project using c++/windows forms (visual studio 2010), we have 4 projects:
- 1个包含GUI窗口形式的项目{受管代码},这是exe项目
- 其他3个项目(非托管代码),都是静态库.
- 在4个项目中,我们不使用预编译的头文件stdafx.h,并且公共语言运行时支持是Pure MSIL公共语言运行时支持(/clr:pure).
- 每个项目都将其他3个项目作为附加的include目录包括在内,并将链接库依赖项设置为yes.
我们有:
警告LNK4221:此目标文件未定义任何以前未定义的公共符号,因此使用该库的任何链接操作都不会使用它
Warning LNK4221: 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
对于同一对象文件(.NETFramework,Version = v4.0.AssemblyAttributes.obj)中的3个静态库项目,出现此警告.
This warning appeared for the 3 static libraries projects in the same object files (.NETFramework,Version=v4.0.AssemblyAttributes.obj).
我们想消除它,但是经过一番搜索,大多数主题都谈到了预编译头,这是我们不使用它的原因.
We want to eliminate it, but after some search, most topics speak about the precompiled headers to be a reason while we don not use it.
关于此警告为何存在以及如何消除此警告的任何新想法?
Any new ideas about why this warning exist and how to eliminate it?
推荐答案
免责声明:此解决方案确实很糟糕,不应将此代码添加到生产版本中!仅隐藏"警告有用.
Disclaimer: This solution is indeed terrible, and this code should not be added to production build! It is only useful to "hide" the warning.
一个更好的解决方案是从编译中删除有问题的文件,因为它总是无用的.
A better solution would be to remove the file in question from the compilation, as it is anyway useless.
该警告有一个问题,该警告源于多个依赖项,我发现这是由于某些翻译单元为空(即源文件为空)引起的.
I had a the problem with this warning originating from several dependencies, and I found that it was caused by some translation unit being empty, i.e. empty source files.
这些文件实际上具有内容,但是已被Visual Studio停用,因此我只是在开始时添加了
These files actually had a content but it was deactivated for visual studio so I just added at the beginning:
__declspec( dllexport ) void getRidOfLNK4221(){}
现在我的项目编译时没有任何警告:)
And now my project compiles without any warning :)
希望这会有所帮助,即使这是一个较晚的答案!
Hope it helps, even if this is a late answer!
这篇关于如何消除Larning LNK4221?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!