【发布时间】:2016-11-18 03:38:07
【问题描述】:
我已经使用这个tutorial 在我的 Rpi 中安装了mosquitto lib。
/usr/local/bin 具有 mosquitto_pub and mosquitto_sub 并且 mosquitto 服务器守护进程位于 /usr/local/sbin。
然后尝试如下链接我的 cmake 文件中的库。
cmake_minimum_required(VERSION 2.6)
PROJECT(MosquittoTest)
# The version number.
set (VERSION_MAJOR 1)
set (VERSION_MINOR 0)
include_directories("${PROJECT_BINARY_DIR}")
# Linked libariries
#For MQTT
#location of raspicam's cmake file is /usr/src/raspicam-0.1.3/build
link_directories(/usr/local/sbin)
target_link_libraries (MosquittoTest mosquitto)
ADD_EXECUTABLE(MosquittoTest MosquittoTest.cpp)
# add the install targets
install (TARGETS MosquittoTest DESTINATION bin)
install (FILES MosquittoInterface.h DESTINATION include)
然后我有错误,因为无法为目标 MosquittoTest 指定链接库。
有人在 gcc make as 中链接了 mosquitto 库
CC = gcc
CFLAGS = -I
DEPS = mosquitto.h
LIBS = -llibmosquitto
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
make: test.c
$(CC) -m32 -Wall -o $@ $^ $(CFLAGS) $(LIBS)
.PHONY: clean
我的 cmake 文件有什么问题?
【问题讨论】:
-
现在解决了。我需要将 libmosquittoop-dev 安装到我的系统中。
-
另一种解决方案是使用 conan 引入 mosquitto,而不是要求安装 debian 软件包,即 mosquitto/1.6.12 确保将 mosquitto:shared=True 放入 conanfile 的 [options] 部分.txt 所以你会有一个库来链接。然后只需将 mosquitto 放入 target_link_libraries 即可。
标签: c++ cmake mosquitto libmosquitto