我是 Mosquitto 的新手,我想写一个简单的 C 客户端连接到 Mosquitto 的测试服务器:http ://test.mosquitto.org/
这是简单 C 客户端的代码,它是 Mosquitto 网站上示例的 99.9%:http: //pastie.org/private/orwicqjfjz8g8biurznca
编辑1:
我按照评论写了一个makefile而不是做
gcc -o test test.c
生成文件如下所示:
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
这是我得到的输出,这似乎是将 mosquitto 库与 gcc 链接起来的一些问题:
Undefined symbols for architecture i386:
"_mosquitto_connect", referenced from:
_main in cc6Blyda.o
"_mosquitto_connect_callback_set", referenced from:
_main in cc6Blyda.o
"_mosquitto_destroy", referenced from:
_main in cc6Blyda.o
"_mosquitto_lib_cleanup", referenced from:
_main in cc6Blyda.o
"_mosquitto_lib_init", referenced from:
_main in cc6Blyda.o
"_mosquitto_log_callback_set", referenced from:
_main in cc6Blyda.o
"_mosquitto_loop", referenced from:
_main in cc6Blyda.o
"_mosquitto_message_callback_set", referenced from:
_main in cc6Blyda.o
"_mosquitto_new", referenced from:
_main in cc6Blyda.o
"_mosquitto_subscribe", referenced from:
_my_connect_callback in cc6Blyda.o
"_mosquitto_subscribe_callback_set", referenced from:
_main in cc6Blyda.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
make: *** [make] Error 1
注意:我使用自制软件安装 mosquitto,所以 lib 的路径是
/usr/local/Cellar/mosquitto/1.1/
感谢任何帮助!
问候