编译 Mosquitto 1.4 时出错

Error compiling Mosquitto 1.4

我曾尝试在 Arch 和 CentOS 7 上编译 Mosquitto,但每次都会出现相同的错误。我想测试 Websocket 功能。

这是我在 CentOS 上使用的程序:

yum group install "Development Tools"

yum install cmake openssl-devel cmake

yum install uuid-devel libxslt docbook5-style-xsl.noarch docbook-style-xsl.noarch

git clone https://github.com/warmcat/libwebsockets.git

cd libwebsockets/

mkdir build;cd build

cmake ..

make

make install

git clone https://git.eclipse.org/r/mosquitto/org.eclipse.mosquitto

cd org.eclipse.mosquitto/

git checkout origin/1.4

vi config.mk

Change "WITH_WEBSOCKETS:=yes"

make

这就是它在 Arch 和 CentOS 上消失的地方:

make[1]: Entering directory '/home/install/org.eclipse.mosquitto/src'
cc -Wall -ggdb -O2  -I. -I.. -I../lib  -DVERSION="\"1.4\""   -DTIMESTAMP="\"2015-05-04 17:17:55+0200\"" -DWITH_BROKER -DWITH_TLS -DWITH_TLS_PSK -DWITH_UUID -DWITH_BRIDGE -DWITH_PERSISTENCE -DWITH_MEMORY_TRACKING -DWITH_SYS_TREE -DWITH_WEBSOCKETS -DWITH_EC -c mosquitto.c -o mosquitto.o

In file included from /usr/include/unistd.h:25:0,
             from mosquitto.c:22:
/usr/include/features.h:148:3: warning: #warning "_BSD_SOURCE and  _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Wcpp]
 # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
mosquitto.c: In function ‘main’:
mosquitto.c:275:101: error: expected expression before ‘,’ token
_mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "mosquitto version %s (build date %s) starting", VERSION, TIMESTAMP);
 mosquitto.c:290:54: error: expected expression before ‘)’ token
snprintf(buf, 1024, "mosquitto version %s", VERSION);
mosquitto.c:368:88: error: expected expression before ‘)’ token
_mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "mosquitto version %s terminating", VERSION);
Makefile:15: recipe for target 'mosquitto.o' failed
make[1]: *** [mosquitto.o] Error 1
make[1]: Leaving directory '/home/install/org.eclipse.mosquitto/src'
Makefile:21: recipe for target 'mosquitto' failed
make: *** [mosquitto] Error 2

如果有人可以指出我做错了什么或遗漏了什么?

出于兴趣,您是否尝试过从此处提供的 Mosquitto 1.4.1 的 TGZ 源代码包构建:

http://mosquitto.org/download/

这些错误看起来与扩展传入的 VERSION 和 TIMESTAMP 值有关。它在 Fedora 20 上构建良好 [除了文档] 应该与 RHEL 7.0(以及从那里到 Centos 7)相差无几。

正如@hardillb 所说,版本定义是问题所在。如果我添加行

#define VERSION

到 mosquitto.c,然后我可以重现您看到的错误,但也会收到有关重新定义 VERSION 的警告。

如果我从 config.mk 中删除 VERSION 的定义,则会收到有关 VERSION 未定义的错误。

这两个都有道理。

您的情况似乎是编译器忽略命令行定义 -DVERSION="\"1.4.1\"" 并将其替换为 -DVERSION=,或者未正确解析字符串。这没有意义。

其他人已经设法在 Arch 上编译,CentOS7 repository 有一个二进制版本 - 但没有 websockets。


经过一些调查,似乎最近的 libwebsockets 代码中存在错误。 This changeset 引入了一些变化,这意味着 libwebsockets 声称宏 VERSION 完全为自己所有,这对图书馆来说不是很礼貌。如果您使用已发布的 libwebsockets 版本,编译应该没有任何问题。