主机系统:ubuntu14.04
openwrt版本:CC
librdkafka版本:0.8.6
1,创建文件夹package/kafka_app
在该文件夹下创建src文件夹和Makefile:
#
# Top level makefile for example application
#
include $(TOPDIR)/rules.mk
PKG_NAME:=kafka_app
PKG_VERSION:=1.0.0
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk
define Package/kafka_app
endef
define Build/Prepare
endef
define Build/Configure
endef
TARGET_CFLAGS += $(FPIC)
define Package/kafka_app/install
endef
$(eval $(call BuildPackage,kafka_app))
2,在package/kafka_app/src/下创建Makefile文件:
MY_LIBS
=
LDFLAGS = -L/home/caosx/openwrt_trunk/staging_dir/target-mips_34kc_musl-1.1.14/root-ar71xx/usr/lib -L/home/caosx/openwrt_trunk/staging_dir/toolchain-mips_34kc_gcc-5.3.0_musl-1.1.14/lib -lrdkafka -latomic
SRCDIRS
=
PROGRAM
= kafka_app
SRCEXTS = .c
HDREXTS = .h
CXXFLAGS= -g -O2
CXX
= arm-linux-g++
RM
= rm -f
ETAGS = etags
ETAGSFLAGS =
CTAGS = ctags
CTAGSFLAGS =
SHELL
= /bin/sh
EMPTY
=
SPACE
= $(EMPTY) $(EMPTY)
ifeq ($(PROGRAM),)
endif
ifeq ($(SRCDIRS),)
endif
SOURCES = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
HEADERS = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(HDREXTS))))
SRC_CXX = $(filter-out %.c,$(SOURCES))
OBJS
= $(addsuffix .o, $(basename $(SOURCES)))
DEPS
= $(OBJS:.o=.d)
## Define some useful variables.
DEP_OPT = $(shell if `$(CC) --version | grep "GCC" >/dev/null`; then \
DEPEND
= $(CC)
$(DEP_OPT)
$(EXTRA_CFLAGS) $(CFLAGS) $(CPPFLAGS)
DEPEND.d
= $(subst -g ,,$(DEPEND))
COMPILE.c
= $(CC)
$(EXTRA_CFLAGS) $(CFLAGS)
-c
#COMPILE.cxx = $(CXX) $(EXTRA_CFLAGS) $(CXXFLAGS)
-c
LINK.c
= $(CC)
$(EXTRA_CFLAGS) $(CFLAGS) $(LDFLAGS)
.PHONY: all objs tags ctags clean distclean help show
.SUFFIXES:
all: $(PROGRAM)
%.d:%.c
objs:$(OBJS)
%.o:%.c
tags: $(HEADERS) $(SOURCES)
ctags: $(HEADERS) $(SOURCES)
$(PROGRAM):$(OBJS)
ifndef NODEP
ifneq ($(DEPS),)
endif
endif
clean:
distclean: clean
# Show help.
help:
# Show variables (for debug use only.)
show:
## End of the Makefile ##
Suggestions are welcome
## All rights reserved ##
##############################################################
3,拷贝example源文件及libkafka.h到src下
4,编译
程序测试见http://blog.sina.com.cn/s/blog_636a55070102wabq.html