交叉编译-mosquitto

版本:
mosquitto-1.4.15 下载

  • 注:1.4.8版本使用本文方法在make install时会报错!

mosquitto-1.4.15

修改config.mk

  • 文件开始地方增加如下:

    1
    2
    3
    4
    5
    6
    CC=arm-linux-gnueabihf-gcc
    CXX=arm-linux-gnueabihf-g++
    CPP=arm-linux-gnueabihf-g++
    AR=arm-linux-gnueabihf-ar
    LD=arm-linux-gnueabihf-ld
    DESTDIR=install_out
  • 在config.mk末尾:
    STRIP定义改为如下

    1
    STRIP?=arm-linux-gnueabihf-strip

    prefix定义改为如下:

    1
    prefix=out
  • 去除一些选项,如不使用SSL等:

    1
    2
    3
    4
    5
    6
    7
    WITH_TLS:=no

    WITH_TLS_PSK:=no

    WITH_SRV:=no

    WITH_UUID:=no

编译

1
2
make
make install

编译出来的mosquitto、客户端、lib分别位于:

1
2
3
mosquitto-1.4.15/src/install_outout/sbin
mosquitto-1.4.15/client/install_outout/bin
mosquitto-1.4.15/lib/install_outout/lib

Error: Invalid user ‘mosquitto’.

把mosquitto-1.4.15/install_out/etc/mosquito/mosquitto.conf.example文件重命名为mosquitto.conf,并修改该文件,把其中#user mosquitto改为user root,root为板子登陆的用户名。再把该mosquitto.conf上传到板子上。

执行

通过-c选项指定mosquitto配置文件加载路径

1
mosquitto -c /etc/mosquitto/mosquitto.conf

订阅消息

1
mosquitto_sub -v -t mqtt_test

发布消息

1
mosquitto_pub -t mqtt_test -m "hello world"