繁体   English   中英

在OSX上将Mosquitto与gcc链接

[英]Link Mosquitto with gcc on OSX

我是Mosquitto的新手,我想编写一个连接到Mosquitto的测试服务器的简单C客户端: 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 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/

感谢任何帮助!

问候

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

这是最终makefile的外观,它不会产生任何链接问题:

CC = gcc

LIBS = -lmosquitto

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

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

.PHONY: clean

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM