visual-studio Visual C++:如何禁用特定的链接器警告?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/661606/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual C++: How to disable specific linker warnings?
提问by Ashwin Nanjappa
I'm using a library from CGAL which during the linking stage of my code compilation produces a lot of linking warnings of this form:
我正在使用来自 CGAL 的库,它在我的代码编译的链接阶段产生了很多这种形式的链接警告:
warning LNK4099: PDB 'vc80.pdb' was not found with 'gmp-vc80-mt-sgd.lib' or at 'vc80.pdb'; linking object as if no debug info
How do I turn off this specific linker warning under Visual C++/Studio 2008?
如何在 Visual C++/Studio 2008 下关闭这个特定的链接器警告?
Note that I do not have any control on the external (CGAL) library which I am using. I cannot/donot want to get into recompiling the external library. Hence, the need to fix the messages at my end.
请注意,我对正在使用的外部 (CGAL) 库没有任何控制权。我不能/不想重新编译外部库。因此,需要在我的最后修复消息。
采纳答案by Aaron Saarela
Add the following as a additional linker option:
添加以下作为附加链接器选项:
 /ignore:4099
This is in Properties->Linker->Command Line
这是在属性->链接器->命令行
回答by John Weldon
Update 2018-10-16
更新 2018-10-16
Reportedly, as of VS 2013, this warning can be disabled. See the comment by @Mark Ransom.
据报道,从 VS 2013 开始,可以禁用此警告。请参阅@Mark Ransom 的评论。
Original Answer
原答案
You can't disable that specific warning.
您无法禁用该特定警告。
According to Geoff Chappellthe 4099 warning is treated as though it's too important to ignore, even by using in conjunction with /wx (which would treat warnings as errors and ignore the specified warning in other situations)
根据Geoff Chappell的说法,4099 警告被视为太重要而无法忽略,即使与 /wx 结合使用(这会将警告视为错误并在其他情况下忽略指定的警告)
Here is the relevant text from the link:
这是链接中的相关文本:
Not Quite Unignorable Warnings
For some warning numbers, specification in a /ignore option is accepted but not necessarily acted upon. Should the warning occur while the /wx option is not active, then the warning message is still displayed, but if the /wx option is active, then the warning is ignored. It is as if the warning is thought important enough to override an attempt at ignoring it, but not if the user has put too high a price on unignored warnings.
The following warning numbers are affected:
4200, 4203, 4204, 4205, 4206, 4207, 4208, 4209, 4219, 4231 and 4237
并非完全不可忽视的警告
对于某些警告编号,可以接受 /ignore 选项中的规范,但不一定会采取行动。如果在 /wx 选项未处于活动状态时出现警告,则仍会显示警告消息,但如果 /wx 选项处于活动状态,则该警告将被忽略。就好像警告被认为足够重要以覆盖忽略它的尝试,但如果用户对未忽略的警告定价过高,则不会。
以下警告编号受到影响:
4200, 4203, 4204, 4205, 4206, 4207, 4208, 4209, 4219, 4231 and 4237
回答by Gurg Hackpof
(For the record and before the thread disappears on the msdn forums) You can't disable the warning (at least under VS2010) because it is on the list of the warnings that can't be disabled (so /wd4099 will not work), but what you can do instead is patch link.exe (usually C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe) to remove it from said list . Sounds like a Hymanhammer, i know. It works though.
(作为记录,并且在 msdn 论坛上的线程消失之前)您不能禁用警告(至少在 VS2010 下),因为它位于无法禁用的警告列表中(因此 /wd4099 将不起作用) ,但您可以做的是修补 link.exe(通常为 C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe)以将其从所述列表中删除。听起来像手提钻,我知道。它虽然有效。
For instance, if you want to remove the warning for 4099, open link.exe with an hex editor, goto line 15A0 which reads 03 10 (little endian for 4099) and replace it with FF 00 (which does not exist.)
例如,如果您想删除 4099 的警告,请使用十六进制编辑器打开 link.exe,转到第 15A0 行,该行读取 03 10(4099 的小端)并将其替换为 FF 00(不存在)。
回答by Minok
For the benefit of others, I though I'd include what I did.
为了他人的利益,我想我会包括我所做的。
Since you cannot get Visual Studio (2010 in my case) to ignore the LNK4204 warnings, my approach was to give it what it wanted: the pdb files. As I was using open source libraries in my case, I have the code building the pdb files already.
由于您无法让 Visual Studio(在我的情况下为 2010)忽略 LNK4204 警告,因此我的方法是为其提供所需的内容:pdb 文件。由于我使用的是开源库,因此我已经有了构建 pdb 文件的代码。
BUT, the default is to name all of the PDF files the same thing: vc100.pdb in my case. As you need a .pdb for each and every .lib, this creates a problem, especially if you are using something like ImageMagik, which creates about 20 static .lib files. You cannot have 20 lib files in one directory (which your application's linker references to link in the libraries from) and have all the 20 .pdb files called the same thing.
但是,默认情况下是将所有 PDF 文件命名为相同的名称:在我的情况下为 vc100.pdb。由于每个 .lib 都需要一个 .pdb,这会产生问题,尤其是当您使用 ImageMagik 之类的东西时,它会创建大约 20 个静态 .lib 文件。您不能在一个目录中拥有 20 个 lib 文件(您的应用程序的链接器引用该目录来链接库中的库)并且将所有 20 个 .pdb 文件称为相同的东西。
My solution was to go and rebuild my static library files, and configure VS2010 to name the .pdb file with respect to the PROJECT. This way, each .lib gets a similarly named .pdb, and you can put all of the LIBs and PDBs in one directory for your project to use.
我的解决方案是去重建我的静态库文件,并配置 VS2010 来命名与 PROJECT 相关的 .pdb 文件。这样,每个 .lib 都会获得一个类似名称的 .pdb,您可以将所有 LIB 和 PDB 放在一个目录中供您的项目使用。
So for the "Debug" configuraton, I edited:
因此,对于“调试”配置,我进行了编辑:
Properties->Configuration Properties -> C/C++ -> Output Files -> Program Database File Namefrom
属性 -> 配置属性 -> C/C++ -> 输出文件 -> 程序数据库文件名来自
$(IntDir)vc$(PlatformToolsetVersion).pdb
$(IntDir)vc$(PlatformToolsetVersion).pdb
to be the following value:
为以下值:
$(OutDir)vc$(PlatformToolsetVersion)D$(ProjectName).pdb
$(OutDir)vc$(PlatformToolsetVersion)D$(ProjectName).pdb
Now rather than somewhere in the intermediate directory, the .pdb files are written to the output directory, where the .lib files are also being written, AND most importantly, they are named with a suffix of D+project name. This means each library projectproduduces a project .lib and a project specific .pdb.
现在,而不是中间目录中的某处,.pdb 文件被写入输出目录,.lib 文件也在其中写入,最重要的是,它们以 D+项目名称的后缀命名。这意味着每个库项目都会产生一个项目 .lib 和一个项目特定的 .pdb。
I'm now able to copy all of my release .lib files, my debug .lib files and the debug .pdb files into one place on my development system, and the project that uses that 3rd party library in debug mode, has the pdb files it needs in debug mode.
我现在可以将我的所有发布 .lib 文件、我的调试 .lib 文件和调试 .pdb 文件复制到我的开发系统上的一个地方,并且在调试模式下使用该 3rd 方库的项目具有 pdb在调试模式下它需要的文件。
回答by zhaorufei
I suspect /ignore is a VC6 link.exe option. for VS2005 and VS2008's linker there's no documented /ignore option available, but the linker looks just ignore the "/ignore:XXX" option, no error and no effect.
我怀疑 /ignore 是一个 VC6 link.exe 选项。对于 VS2005 和 VS2008 的链接器,没有记录在案的 /ignore 选项可用,但链接器看起来只是忽略了“/ignore:XXX”选项,没有错误也没有效果。
回答by dirkgently
The PDB file is typically used to store debug information. This warning is caused probably because the file vc80.pdbis not found when linking the target object file. Read the MSDN entry on LNK4099 here.
PDB 文件通常用于存储调试信息。该警告可能是因为vc80.pdb在链接目标对象文件时未找到该文件。在此处阅读有关 LNK4099 的 MSDN 条目。
Alternatively, you can turn off debug information generation from the Project Properties > Linker > Debugging > Generate Debug Info field.
或者,您可以从 Project Properties > Linker > Debugging > Generate Debug Info 字段中关闭调试信息生成。
回答by ax.
EDIT: don't use vc80 / Visual Studio 2005, but Visual Studio 2008 / vc90 versions of the CGAL library (maybe fromhere).
编辑:不要使用 vc80 / Visual Studio 2005,而是使用 CGAL 库的 Visual Studio 2008 / vc90 版本(可能来自此处)。
You could also compile with /Z7, so the pdb doesn't need to be used, or remove the /DEBUG linker option if you do not have .pdb files for the objects you are linking.
您还可以使用 /Z7 进行编译,因此不需要使用 pdb,或者如果您没有链接对象的 .pdb 文件,则删除 /DEBUG 链接器选项。
回答by KindDragon
You cannot disable linker warning 4099, as said @John Weldon.
正如@John Weldon 所说,您不能禁用链接器警告 4099。
You should rebuild library with some project configuration changes. You have several options:
您应该使用一些项目配置更改来重建库。您有多种选择:
- Save PDB file with debug information is same folder where you save .lib file. Set value "$(OutDir)$(TargetName).pdb" to Properties->C/C++->Output Files-Program Database File Name
- Save debug information in .lib file. Set value "C7 compatible (/Z7)" to Properties->C/C++->General->Debug Information Format
- Disable generation debug information for this library. Remove value from Properties->C/C++->General->Debug Information Format
- 保存带有调试信息的 PDB 文件与保存 .lib 文件的文件夹相同。将值“$(OutDir)$(TargetName).pdb”设置为 Properties->C/C++->Output Files-Program Database File Name
- 将调试信息保存在 .lib 文件中。将值“C7 compatible (/Z7)”设置为 Properties->C/C++->General->Debug Information Format
- 禁用此库的生成调试信息。从 Properties->C/C++->General->Debug Information Format 中删除值

