构建过程中的警告信息 - >警告:“布尔”重新定义

问题描述 投票:0回答:1

我使用的代码::块重写一个Python(含Mosquitto MQTT)脚本到C。作为测试我使用的Mosquitto库中找到下面的代码:

https://bitbucket.org/oojah/mosquitto/src/4deedcb49ff50be94166701f21e5c79ff7667d5b/test/lib/c/02-subscribe-qos0.c?at=default

然而,这将导致以下警告:

||=== Build: Debug in test (compiler: GNU GCC Compiler) ===|
..\..\..\..\..\Program Files (x86)\mosquitto\devel\mosquitto.h|56|warning: "bool" redefined|
c:\mingw32-xy\bin\..\lib\gcc\mingw32\4.5.2\include\stdbool.h|33|note: this is the location of the previous definition|
obj\Debug\main.o||In function `on_connect':|

我已经挖掘到的主题,我认为它可以使用包括警卫来解决。我已经做了一些测试,但显然我不知道如何正确地应用它们。

由于我不是一个有经验的C程序员,我决定打电话给一些帮助。

编辑:我已经添加了链接mosquitto.h code

这是它可能会出问题的部分:

#ifndef _MOSQUITTO_H_
#define _MOSQUITTO_H_

#ifdef __cplusplus
extern "C" {
#endif

#if defined(WIN32) && !defined(WITH_BROKER)
#   ifdef libmosquitto_EXPORTS
#       define libmosq_EXPORT  __declspec(dllexport)
#   else
#       define libmosq_EXPORT  __declspec(dllimport)
#   endif
#else
#   define libmosq_EXPORT
#endif

#ifdef WIN32
#   ifndef __cplusplus
#       define bool char
#       define true 1
#       define false 0
#   endif
#else
#   ifndef __cplusplus
#       include <stdbool.h>
#   endif
#endif

是否有一个快速修复,使其工作?

c gcc-warning mosquitto
1个回答
2
投票

包括卫兵是没有问题的,没错。

的问题是,mosquitto.h包含宏bool,这已经通过<stdbool.h>定义的重新定义。

这似乎只触发的Win32。这可能是有人假设的结果,“如果我们正在构建在Win32,那么我们就不能使用符合C99编译器,因此,我们必须替换为我们自己的stdbool.h兼容的声明”。

这当然是不正确的假设;您可以在Win32的非微软的编译器就好建设。这可能是你在做什么;代码::块可以使用GCC。

我想说在mosquitto.h逻辑需要修理。

© www.soinside.com 2019 - 2024. All rights reserved.