在OSX上将Mosquitto与gcc联系起来

时间:2013-04-16 11:32:58

标签: c gcc gcc-warning llvm-gcc mqtt

我是Mosquitto的新手,我想写一个连接到Mosquitto测试服务器的简单C客户端:http://test.mosquitto.org/

以下是简单C客户端的代码,它是Mosquitto网站上99.9%的示例:http://pastie.org/private/orwicqjfjz8g8biurznca

编辑1:

我按照评论写了一个makefile而不是做

gcc -o test test.c

makefile如下所示:

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 libs与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/

感谢任何帮助!!

此致

1 个答案:

答案 0 :(得分:1)

我通过makefile中的一些试错来解决了链接问题。

这是最终的makefile看起来如何,它没有给出任何链接问题:

CC = gcc

LIBS = -lmosquitto

%.o: %.c 
    $(CC) -c -o $@ $< 

make: test.c
    $(CC) -Wall -o test $^ $(LIBS)

.PHONY: clean

由于