我使用的代码::块重写一个Python(含Mosquitto MQTT)脚本到C。作为测试我使用的Mosquitto库中找到下面的代码:
然而,这将导致以下警告:
||=== 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
是否有一个快速修复,使其工作?
包括卫兵是没有问题的,没错。
的问题是,mosquitto.h
包含宏bool
,这已经通过<stdbool.h>
定义的重新定义。
这似乎只触发的Win32。这可能是有人假设的结果,“如果我们正在构建在Win32,那么我们就不能使用符合C99编译器,因此,我们必须替换为我们自己的stdbool.h
兼容的声明”。
这当然是不正确的假设;您可以在Win32的非微软的编译器就好建设。这可能是你在做什么;代码::块可以使用GCC。
我想说在mosquitto.h
逻辑需要修理。