您的位置:首页 > 其它

librdkafka 0.7 编译失败解决办法

2013-07-16 10:38 1451 查看
Kafka MQ是一个高吞吐量分布式消息系统,是由LinkedIn开源的消息中间件。原生的Kafka是由Java实现的,当需要应用到C/C++环境时,需要C/C++的接口。librdkafka是一个C语言的Kafka API,也是Kafka官网推荐使用的C语言API,作者是Magnus Edenhill。这里使用的版本是librdkafka 0.7。

昨天在Linux上编译librdkafka,发现编译失败。make all,出现如下提示:

cc -MD -MP -O2 -Wall -Werror -Wfloat-equal -Wpointer-arith -fPIC -I. -g -c rdkafka.c
cc1: warnings being treated as errors
rdkafka.c: In function 'rd_kafka_q_pop':
rdkafka.c:551: warning: implicit declaration of function 'TAILQ_FIRST'
rdkafka.c:551: warning: assignment makes pointer from integer without a cast
make: *** [rdkafka.o] Error 1


在网上搜了好久,都找不到解决办法。

今天,请教了一下同事,解决办法其实很简单,把gcc的选项 -Werror 去掉就可以了,在 Makefile 中直接修改。

man gcc,-Werror 的含义是 Make all warnings into errors,其实上面的 “warnings being treated as errors” 已经说得很明显,只是自己很少用 make,所以脑子一时转不过来,以为只要make 加上 -i 选项去忽略 warning即可,殊不知,应当是在 gcc 的选项中去忽略 warning ,感觉自己弱爆了。= =

下午,又遇到一个问题,在example中make ,出现undefined reference to `__sync_sub_and_fetch_4',google 之说是GCC的版本太老,最简单的办法就是升级一下。当然不升级也可以,在命令行中输入arch。假如输出是"i686",那么,在 librdkafka 目录下的 Makefile 的 CFLAGS 中加上选项 -march=i686,重新make all 和 make install。应该就可以解决这个问题了。

GCC 的手册中,对 -march 的作用说明如下。

-march=name

This specifies the name of the target ARM architecture. GCC uses this name to determine what kind of instructions it can emit when generating assembly code.

最后,如果你跟我一样不幸,又蹦出一个这样的问题 undefined reference to `TAILQ_FIRST',那么是你的 sys/queue.h 太老了。当然,最简单的就是升级一下系统了,这个系统文件太老了。

如果不方便升级系统,那可以在 http://linux.die.net/include/sys/queue.h 下载 queue.h,放在 librdkafka目录下。然后把所有#include <sys/queue.h>替换为#include "queue.h"。再次重新make all 和 make install。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐