From 3ba07090485354a70a56a2d10b1f2ee5fd475163 Mon Sep 17 00:00:00 2001 From: Kaikai <98205900+Kaikaikaifang@users.noreply.github.com> Date: Tue, 19 Nov 2024 19:14:15 -0800 Subject: [PATCH] fix(example): c++14 limitation (#19292) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix the bug: ```shell ‘std::string_view’ is only available from C++17 onwards ``` The error occurs because the code is being compiled using the C++14 standard, which does not include the std::string_view type introduced in C++17. The Abseil library (absl), used by Protocol Buffers, includes absl/strings/string_view.h, which uses std::string_view. This causes the compilation to fail in environments configured with C++14 or earlier. In the provided build system, the file add_person.cc is being compiled using the -std=c++14 flag, which is incompatible with code depending on features from C++17 (e.g., std::string_view). Closes #19292 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/19292 from Kaikaikaifang:patch-1 ee276ffd0b130024a408526366c63d46889e2118 PiperOrigin-RevId: 698223950 --- examples/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Makefile b/examples/Makefile index f7ee9b116d..5290fdb03f 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -46,11 +46,11 @@ protoc_middleman_ruby: addressbook.proto add_person_cpp: add_person.cc protoc_middleman pkg-config --cflags protobuf # fails if protobuf is not installed - c++ -std=c++14 add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf` + c++ add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf` list_people_cpp: list_people.cc protoc_middleman pkg-config --cflags protobuf # fails if protobuf is not installed - c++ -std=c++14 list_people.cc addressbook.pb.cc -o list_people_cpp `pkg-config --cflags --libs protobuf` + c++ list_people.cc addressbook.pb.cc -o list_people_cpp `pkg-config --cflags --libs protobuf` add_person_dart: add_person.dart protoc_middleman_dart