主机系统: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
SECTION:=utils
CATEGORY:=Utilities
DEPENDS:=+librdkafka +libatomic
TITLE:=kafka_app -- prints kafka_app 1 to 99
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)
endef
define Build/Configure
endef
TARGET_CFLAGS += $(FPIC)
define Package/kafka_app/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/kafka_app $(1)/bin/
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),)
CUR_PATH_NAMES = $(subst /,$(SPACE),$(subst $(SPACE),_,$(CURDIR)))
PROGRAM = $(word $(words $(CUR_PATH_NAMES)),$(CUR_PATH_NAMES))
ifeq ($(PROGRAM),)
PROGRAM = a.out
endif
endif
ifeq ($(SRCDIRS),)
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 \
echo "-MM -MP"; else echo "-M"; fi )
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
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
objs:$(OBJS)
%.o:%.c
$(COMPILE.c) $< -o $@
tags: $(HEADERS) $(SOURCES)
$(ETAGS) $(ETAGSFLAGS) $(HEADERS) $(SOURCES)
ctags: $(HEADERS) $(SOURCES)
$(CTAGS) $(CTAGSFLAGS) $(HEADERS) $(SOURCES)
$(PROGRAM):$(OBJS)
$(LINK.c) $(OBJS) $(MY_LIBS) -o $@
@echo Type ./$@ to execute the program.
ifndef NODEP
ifneq ($(DEPS),)
sinclude $(DEPS)
endif
endif
clean:
$(RM) $(OBJS) $(PROGRAM) $(PROGRAM).exe
distclean: clean
$(RM) $(DEPS) TAGS
# Show help.
help:
@echo 'Generic Makefile for C/C++ Programs (gcmakefile) version 0.5'
@echo 'Copyright (C) 2007, 2008 whyglinux '
@echo
@echo 'Usage: make [TARGET]'
@echo 'TARGETS:'
@echo ' all (=make) compile and link.'
@echo ' NODEP=yes make without generating dependencies.'
@echo ' objs compile only (no linking).'
@echo ' tags create tags for Emacs editor.'
@echo ' ctags create ctags for VI editor.'
@echo ' clean clean objects and the executable file.'
@echo ' distclean clean objects, the executable and dependencies.'
@echo ' show show variables (for debug use only).'
@echo ' help print this message.'
@echo
@echo 'Report bugs to .'
# Show variables (for debug use only.)
show:
@echo 'PROGRAM :' $(PROGRAM)
@echo 'SRCDIRS :' $(SRCDIRS)
@echo 'HEADERS :' $(HEADERS)
@echo 'SOURCES :' $(SOURCES)
@echo 'SRC_CXX :' $(SRC_CXX)
@echo 'OBJS :' $(OBJS)
@echo 'DEPS :' $(DEPS)
@echo 'DEPEND :' $(DEPEND)
@echo 'COMPILE.c :' $(COMPILE.c)
@echo 'COMPILE.cxx :' $(COMPILE.cxx)
@echo 'link.c :' $(LINK.c)
@echo 'link.cxx :' $(LINK.cxx)
## 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