我正在try 将GRPC c++示例代码移植到Yocto Build.我正在使用Yocto 2.2(Morty).目前,我能够将Protobuf 3.3.0和GRPC 1.4.3集成到Yocto构建中.使用较旧的版本,因为我所有的层都来自莫蒂分支.这是我的食谱你好.
DESCRIPTION = "Working example for grpc"
AUTHOR = ""
LICENSE = "Apache-2.0"
HOMEPAGE = ""
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
DEPENDS = "grpc golang protobuf3 c-ares zlib openssl"
RDEPENDS_${PN} += "libstdc++"
SRCREV = "29a2a533c98aa21f05c8f598ef2b47321508d5da"
BRANCH = "v1.4.x"
SRC_URI = "gitsm://github.com/grpc/grpc.git;protocol=https;name=grpc;branch=${BRANCH}"
PR = "r0"
S = "${WORKDIR}/git"
EXTRA_OECMAKE = "-DRUN_HAVE_STD_REGEX=1 \
-DRUN_HAVE_POSIX_REGEX=0 \
-DRUN_HAVE_STEADY_CLOCK=0 \
-DTHREADS_PTHREAD_ARG=2 \
-DBUILD_DEPS=ON \
-DHAVE_STD_REGEX=ON \
-DRUN_HAVE_STD_REGEX=1 \
"
do_compile() {
cd ${S}/examples/cpp/helloworld/
make all
}
FILES_${PN} += "${bindir}/*"
do_install() {
install -d ${D}${bindir}
install -m 0755 ${S}/examples/cpp/helloworld/greeter_client ${D}${bindir}
install -m 0755 ${S}/examples/cpp/helloworld/greeter_server ${D}${bindir}
}
我正在使用git的Makefile.我已经修改了几条路径.所以我现在的Makefile是
HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
SYSTEM ?= $(HOST_SYSTEM)
CXX = g++
CXXFLAGS += -I/home/src/build/tmp/work/armv5e-linux-gnueabi/protobuf3/3.3.0-r0/sysroot-destdir/usr/include/ -pthread
CXXFLAGS += -I/home/src/build/tmp/work/armv5e-linux-gnueabi/protobuf3/3.3.0-r0/sysroot-destdir/usr/lib/ -pthread
#CPPFLAGS += -I/usr/local/include -pthread
CXXFLAGS += -std=c++11
ifeq ($(SYSTEM),Darwin)
LDFLAGS += -L/home/src/build/tmp/work/armv5e-linux-gnueabi/grpc/1.4.3-r0/sysroot-destdir/usr/lib `pkg-config --libs grpc++ grpc` \
-lgrpc++_reflection \
-lprotobuf -lpthread -ldl
else
LDFLAGS += -L/home/src/build/tmp/work/armv5e-linux-gnueabi/grpc/1.4.3-r0/sysroot-destdir/usr/lib `pkg-config --libs grpc++ grpc` \
-Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed \
-lprotobuf -lpthread -ldl
endif
PROTOC = protoc
GRPC_CPP_PLUGIN = grpc_cpp_plugin
GRPC_CPP_PLUGIN_PATH = "/home/src/build/tmp/work/armv5e-linux-gnueabi/hello/1.4.3-r0/git/vsprojects/vcxproj/"
PROTOS_PATH = ../../protos
vpath %.proto $(PROTOS_PATH)
all: system-check greeter_client greeter_server
greeter_client: helloworld.pb.o helloworld.grpc.pb.o greeter_client.o
$(CXX) $^ $(LDFLAGS) -o $@
greeter_server: helloworld.pb.o helloworld.grpc.pb.o greeter_server.o
$(CXX) $^ $(LDFLAGS) -o $@
.PRECIOUS: %.grpc.pb.cc
%.grpc.pb.cc: %.proto
$(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
.PRECIOUS: %.pb.cc
%.pb.cc: %.proto
$(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
clean:
rm -f *.o *.pb.cc *.pb.h greeter_client greeter_server
# The following is to test your system and ensure a smoother experience.
# They are by no means necessary to actually compile a grpc-enabled software.
PROTOC_CMD = which $(PROTOC)
PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q libprotoc.3
PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN)
HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false)
ifeq ($(HAS_PROTOC),true)
HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
endif
HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false)
SYSTEM_OK = false
ifeq ($(HAS_VALID_PROTOC),true)
ifeq ($(HAS_PLUGIN),true)
SYSTEM_OK = true
endif
endif
system-check:
ifneq ($(HAS_VALID_PROTOC),true)
@echo " DEPENDENCY ERROR"
@echo
@echo "You don't have protoc 3.0.0 installed in your path."
@echo "Please install Google protocol buffers 3.0.0 and its compiler."
@echo "You can find it here:"
@echo
@echo " https://github.com/google/protobuf/releases/tag/v3.0.0"
@echo
@echo "Here is what I get when trying to evaluate your version of protoc:"
@echo
-$(PROTOC) --version
@echo
@echo
endif
ifneq ($(HAS_PLUGIN),true)
@echo " DEPENDENCY ERROR"
@echo
@echo "You don't have the grpc c++ protobuf plugin installed in your path."
@echo "Please install grpc. You can find it here:"
@echo
@echo " https://github.com/grpc/grpc"
@echo
@echo "Here is what I get when trying to detect if you have the plugin:"
@echo
-which $(GRPC_CPP_PLUGIN)
@echo
@echo
endif
ifneq ($(SYSTEM_OK),true)
@false
endif
因此,我面临的问题是,当make文件运行proc命令时,它使用来self 的主机的proc,而不是Yocto构建.即3.21.12版本,该版本使用来自Yocto Build的协议Buf(3.3.0)引发错误
|在helloworld.pb.cc:4:0包含的文件中: |helloworld.pb.h:10:10:致命错误:google/Protobuf/port_Def.inc.没有这样的文件或目录 |#INCLUDE<;GOOGLE/PROTOBUF/port_Def.inc>; |^~ |编译已终止. |:目标‘helloworld.pb.o’的配方失败 |make:*[helloworld.pb.o]错误1 |警告:退出shell 命令的代码2.
我试着在hello.bb菜谱中使用了proc命令,它也是从主机使用的.
那么,有没有办法在Makefile中使用Yocto Build中的Protoc呢?