dpdk 源代码是用 c 语言编写的。example 目录下的例子也都是 c 语言代码,编译时默认使用 gcc 编译。如果用户想仿照这些例子编写自己的 c++ 源码,那么第一个问题便是编译器的问题,因为 gcc 无法编译 c++ 代码。dpdk 邮件组里的 Daniel Kan 给出了如下的解决方案,涉及到 mk/internal/rte.compile-pre.mk 和 mk/toolchain/gcc/rte.vars.mk 两个文件:
1. 修改 mk/internal/rte.compile-pre.mk
以下是修改后的文件和修改前文件的 diff 结果:
@@ -33,11 +33,14 @@
# Common to rte.lib.mk, rte.app.mk, rte.obj.mk
#
+CXX-suffix = cpp
+
SRCS-all := $(SRCS-y) $(SRCS-n) $(SRCS-)
# convert source to obj file
src2obj = $(strip $(patsubst %.c,%.o,\
- $(patsubst %.S,%_s.o,$(1))))
+ $(patsubst %.$(CXX-suffix),%.o,\
+ $(patsubst %.S,%_s.o,$(1)))))
# add a dot in front of the file name
dotfile = $(strip $(foreach f,$(1),\
@@ -46,12 +49,14 @@
# convert source/obj files into dot-dep filename (does not
# include .S files)
src2dep = $(strip $(call dotfile,$(patsubst %.c,%.o.d, \
- $(patsubst %.S,,$(1)))))
+ $(patsubst %