boost::system::(...)_category 已定义但未使用

发布于 2024-08-13 01:18:14 字数 603 浏览 9 评论 0原文

我目前收到的编译器警告类似于我在问题标题中给出的警告。警告,例如...

警告:'boost::system::generic_category'已定义但未使用

警告:'boost::system::posix_category'已定义但未使用 >

警告:'boost::system::errno_ecat'已定义但未使用

警告:'boost::system::native_ecat'已定义但未使用

据我所知该程序没有受到任何影响。然而,我不喜欢警告挂在身边,但我不知道这些警告试图告诉我什么,除了与 boost 相关的定义和相关内容挂在未使用的地方。然而,我已经使用了我定义的所有内容。我使用的 boost 库是随机库和文件系统库。

当我检查警告来源时,它会显示 Boost 的 error_category.hpp 文件,并突出显示一些被注释为“预定义错误类别”或“不推荐使用的同义词”的静态常量。也许问题与我使用该库时的错误处理(或缺乏)有关?

任何人都可以深入了解为什么会出现这些警告吗?我完全错过了什么吗?

PS 警告处于最高级别。

I'm currently getting compiler warnings that resemble the warning I gave in the question title. Warnings such as....

warning: 'boost::system::generic_category' defined but not used

warning: 'boost::system::posix_category' defined but not used

warning: 'boost::system::errno_ecat' defined but not used

warning: 'boost::system::native_ecat' defined but not used

As far as I know the program isn't being affected in any way. However, I don't like warnings hanging around, but I have no idea what these warnings are trying to tell me besides that something defined and related to boost is hanging around somewhere not being used. However, everything that I've defined, I've used. The boost libraries I'm using are the random library and the filesystem library.

When I check the source of the warning it brings up Boost's error_category.hpp file and highlights some static consts that are commented as either "predefined error categories" or "deprecated synonyms". Maybe the problem has something to do with my error handling (or lack of) when using the library?

Can anyone give some insight regarding why these warnings are popping up? Am I completely missing something?

P.S. Warnings are at max level.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

携余温的黄昏 2024-08-20 01:18:14

我同意@Charles Salvia 的观点,但想补充一点,至少从 Boost 1.44.0 开始,这些定义现在已经被包装起来——被排除为已弃用。因此,如果您不使用它们,只需在包含头文件之前包含以下行:

#ifndef BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED 1
#endif

I agree with @Charles Salvia, but wanted to add that at least as of Boost 1.44.0, these definitions are now wrapped -- to be excluded as deprecated. So if you aren't using them, just include the following lines before you include the header file:

#ifndef BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED 1
#endif
不必你懂 2024-08-20 01:18:14

这与Boost.System库中的error_code库有关。 Boost error_codes 包含两个属性:值和类别。为了使 error_codes 可扩展,以便库用户可以设计自己的错误类别,boost 设计者需要某种方法来表示唯一的错误代码类别。简单的 ID 号是不够的,因为这可能会导致两个项目对自定义错误类别使用冲突的 ID 号。

所以基本上,他们所做的就是使用从基类 error_category 继承的静态对象形式的内存地址。这些变量除了充当特定错误类别的唯一标识符之外实际上不执行任何操作。因为它们本质上是在内存中具有唯一地址的静态虚拟对象,所以您可以轻松创建自己的自定义错误类别,这不会干扰其他错误类别“ID”。请参阅此处了解更多信息。

我想您所看到的是这个设计决策的副作用。由于这些变量从未在您的程序中实际使用,因此编译器会生成警告。我只想说,我不认为你做错了什么。

This relates to the error_code library in the Boost.System library. Boost error_codes contain two attributes: values and categories. In order to make error_codes extensible so that library users can design their own error categories, the boost designers needed some way to represent a unique error code category. A simple ID number wouldn't suffice, because this could result in two projects using conflicting ID numbers for custom error categories.

So basically, what they did was to use memory addresses, in the form of static objects that inherit from the base class error_category. These variables don't actually do anything except to serve as unique identifiers of a certain error category. Because they are essentially static dummy objects with unique addresses in memory, you can easily create your own custom error categories which won't interfere with other error category "IDs." See here for more information.

I suppose that what you're seeing is a side-effect of this design decision. Since these variables are never actually used in your program, the compiler is generating warnings. Suffice it to say, I don't think you're doing anything wrong.

﹉夏雨初晴づ 2024-08-20 01:18:14

我尝试了 @M.Tibbits 建议的 BOOST_SYSTEM_NO_DEPRECATED,它似乎删除了一些警告实例(在 Linux 下构建的大型系统中),但不是全部。

然而,使用 -isystem 而不是 -I 来包含 boost 标头(并忽略它们的问题)对我来说确实有效。

建议者 https: //exceptionshub.com/how-do-you-disable-the-unused-variable-warnings-coming-out-of-gcc.html

由 GNU GCC 解释(间接):http://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html

I tried the BOOST_SYSTEM_NO_DEPRECATED suggested by @M.Tibbits, and it seemed to remove some instances of the warnings (in a big system built under linux), but not all.

However, using -isystem instead of -I to include the boost headers (and ignore their problems) did work for me.

Suggested by https://exceptionshub.com/how-do-you-disable-the-unused-variable-warnings-coming-out-of-gcc.html

Explained (obliquely) by GNU GCC: http://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文