简体   繁体   English

使用VC ++编译SQLite时如何解决警告?

[英]How do I address warnings when compiling SQLite with VC++?

Whenever I compile SQLite with Visual C++ 9 I get hundreds of warnings, such as 每当我使用Visual C ++ 9编译SQLite时 ,都会收到数百条警告,例如

  • potentially uninitialized variables 潜在的未初始化变量
  • conversion from wider integer types to narrower integer types 从较宽的整数类型到较窄的整数类型的转换
  • signed/unsigned integers mismatches. 有符号/无符号整数不匹配。

I'm not alone - there's an SQLite FAQ question specifically about that. 我并不孤单-有一个专门针对此的SQLite FAQ问题 The answer to that question says that 这个问题的答案说

  • those warnings don't arise in GCC that SQLite developers use 这些警告不会出现在SQLite开发人员使用的GCC中
  • warnings are not that of a problem since the team tests code thorougly 警告不是问题,因为团队彻底地测试了代码

Of course I can't argue against those points, but... 我当然不能反对这些观点,但是...

  • I don't use GCC - I use VC++ and VC++ does show warnings 我不使用GCC-我使用VC ++,并且VC ++确实显示警告
  • they tested the code compiled with GCC and I don't use GCC, so there might be some implementation-defined difference or something like different levels of C standard compliance between GCC and VC++ that will subtly break the code with severe consequences. 他们测试了使用GCC编译的代码,而我不使用GCC,因此GCC和VC ++之间可能存在一些实现定义的差异或不同级别的C标准合规性,这些都会巧妙地破坏代码,并带来严重的后果。

That's why I don't like the idea of simply ignoring all warnings. 这就是为什么我不喜欢简单地忽略所有警告的想法的原因。

So how do I deal with warnings VC++ displays when compiling SQLite? 那么在编译SQLite时如何处理VC ++显示的警告?

Why not use #pragmas to disable these warnings if they're not actually causing any harm? 如果实际上没有造成任何危害,为什么不使用#pragmas禁用这些警告? Or switch to a lower warning level (as I assume you have the SQLite source as a separate VC lib project?) 还是切换到较低的警告级别(假设您拥有SQLite源作为单独的VC lib项目?)

How does any developer working with C++ deal with warnings? 任何使用C ++的开发人员如何处理警告? Investigate the code about which you're receiving the warning, determine if the warning is telling you something you need to know, and then change the code if needed. 研究收到警告的代码,确定警告是否告诉您需要了解的信息,然后根据需要更改代码。 I'm not sure I really understand your question. 我不确定我是否真的理解您的问题。

Maybe if you posted a specific warning (with code) we might be able to advise you about what you need to do about it. 也许,如果您发布了特定的警告(带有代码),我们可能会为您提供有关该警告的建议。

I would say that compiling something as complicated as SQLite, using a compiler and libraries the developers themselves say they never use, is doomed to failure, or at the least will be very, very painful. 我要说的是,使用开发人员自己从未使用过的编译器和库来编译像SQLite这样复杂的东西,注定会失败,或者至少会非常非常痛苦。 GCC is easy to install and use on Windows (get it from http://tdragon.net/recentgcc ), so why not use it? GCC在Windows上易于安装和使用(可从http://tdragon.net/recentgcc获得),那么为什么不使用它呢?

First, remember that warnings are not error indicators. 首先,请记住警告不是错误指示符。 They're there to draw the developers' attention to things that could indicate errors, and nothing else. 他们在那里是为了吸引开发人员注意那些可能指示错误的内容,而没有别的。

If the code works, the number of warnings emitted is pretty much irrelevant. 如果该代码有效,则发出的警告数量几乎无关紧要。

If you want to play it safe, look at the warnings: Are any of them related to implementation-defined behavior which is handled differently by VS and GCC? 如果您想放心,请查看以下警告:它们是否与VS和GCC处理不同的实现定义的行为有关? If so, you might have a problem. 如果是这样,您可能有问题。 But as long as the warnings are about things that are handled identically by both compilers (such as integer/double conversions), it can be ignored. 但是,只要警告是关于两个编译器都相同地处理的事情(例如整数/双精度转换),就可以将其忽略。

As I recall (been a while since I compiled SQLite on VS without silencing warnings), virtually all the warnings are about implicit conversions between built-in types, all of which are perfectly safe, as long as the developer is aware they're taking place. 我记得(一段时间以来,我在VS上编译SQLite时没有沉默警告),实际上所有警告都是关于内置类型之间的隐式转换的,只要开发人员知道它们正在使用,所有这些都是绝对安全的地点。

SQLite works just fine on VS though. SQLite在VS上工作得很好。 The library is widely used by a lot of big projects. 该库被许多大型项目广泛使用。 It is tested fairly extensively. 经过相当广泛的测试。

Select the files in the VC9 solution explorer, right-click, choose "properties". 在VC9解决方案资源管理器中选择文件,右键单击,选择“属性”。 Then go to the C++ -> General tab and set the Warning level to Off . 然后转到C++ -> General选项卡,并将Warning level设置为Off That will turn off all warnings for those files only. 这将仅关闭那些文件的所有警告。

I do that with most of the external lib files I use: there's no gain to 'fix' those (if they're not really bugs), and turning off the warnings helps to keep the build output window clean so I don't miss warnings in my own code. 我使用的大多数外部lib文件都是这样做的:没有“修复”那些文件的好处(如果它们不是真正的bug),并且关闭警告有助于保持构建输出窗口的清洁,因此我不会错过我自己的代码中的警告。

What these warnings basically mean is that: 这些警告的基本含义是:

  1. If you port the code to an environment where all the basic types (char, short, int, long, long long) are exactly the same size as what the original developers used and tested with, the code will probably work as tested (although watch out for those possibly uninitialized variables), but 如果将代码移植到所有基本类型(char,short,int,long,long long)的大小与原始开发人员使用和测试过的大小完全相同的环境,则该代码可能会在测试后正常工作(尽管请注意排除那些可能未初始化的变量),但是

  2. If you ever port the code to an environment where some of the basic types are different sizes from what the the original developers used, you have a good chance of the code breaking in mysterious and counter-intuitive ways at some of the places where you are getting these warnings. 如果您曾经将代码移植到某些基本类型与原始开发人员使用的大小不同的环境中,那么您很有可能在您所处的某些地方以神秘和违反直觉的方式破坏代码得到这些警告。 That can be true even if you use GCC in both environments. 即使您在两种环境中都使用GCC,也是如此。 See the C FAQ 3.19 for some examples of the kind of behavior that can occur (keeping in mind that both C and C++ standards now mandate the "value-preserving" rules). 有关可能发生的行为的一些示例,请参见C FAQ 3.19 (请记住,C和C ++标准现在都规定了“保值”规则)。

It's a sign of sloppy coding. 这是草率编码的标志。 They really should fix most of the issues leading to these warnings (typically, mixing signed and unsigned types across a binary operator is risky, and I bet they are doing that a lot here). 他们确实应该解决导致这些警告的大多数问题(通常,在二进制运算符之间混合有符号和无符号类型是有风险的,我敢打赌他们在这里经常这样做)。 I've fixed other people's code that has led to such warnings in the past, making it more robust for porting to future environments. 我已经修复了过去导致此类警告的其他人的代码,使其更强大地移植到将来的环境中。 But that said, if they are compiling and testing with the same basic type sizes that you will be using (which they almost certainly are if there's a compatible C-language interface to link to), then you probably can get away without fixing many of these problems. 但这就是说,如果它们使用与您将使用的相同的基本类型大小进行编译和测试(如果可以链接到兼容的C语言接口,则几乎可以肯定它们的大小),那么您可能无需解决许多这些问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM