gpt4 book ai didi

c - 构建期间的警告消息 --> 警告 : "bool" redefined

转载 作者:太空宇宙 更新时间:2023-11-04 08:39:07 26 4
gpt4 key购买 nike

我正在使用 Code::Blocks 将 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':|

我一直在深入研究这个主题,我认为可以使用 include guards 来解决。我做了一些测试,但显然我不知道如何正确应用它们。

由于我不是经验丰富的 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

是否有快速解决方案使其正常工作?

最佳答案

确切地说,包括守卫不是问题。

问题是 mosquitto.h 包含宏的重新定义 bool ,它已经由 <stdbool.h> 定义.

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

当然,这是一个错误的假设;您可以在 Win32 中使用非 Microsoft 编译器构建。那可能就是你正在做的; Code::Blocks 可以使用 GCC。

我会说 mosquitto.h 中的逻辑需要修复。

关于c - 构建期间的警告消息 --> 警告 : "bool" redefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24605917/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com