0

I'm learning to use protobuf, so I tried the official example from v23.4.

At the first time, I'm using the system package manager pacman to install protobuf, here's my version:

 sudo pacman -Q protobuf
protobuf 23.4-1
 sudo pacman -Q abseil-cpp
abseil-cpp 20230125.3-1

but when i make cpp, I got lots of errors, I intercept a part of it, is it long enough to show the problem?

In file included from /usr/include/google/protobuf/stubs/common.h:44,
                 from /usr/include/google/protobuf/io/coded_stream.h:130,
                 from /usr/include/google/protobuf/duration.pb.h:24,
                 from /usr/include/google/protobuf/util/time_util.h:53,
                 from add_person.cc:5:
/usr/include/absl/strings/string_view.h:52:26: error: ‘string_view’ in namespace ‘std’ does not name a type
   52 | using string_view = std::string_view;
      |                          ^~~~~~~~~~~
/usr/include/absl/strings/string_view.h:52:21: note: ‘std::string_view’ is only available from C++17 onwards
   52 | using string_view = std::string_view;
      |                     ^~~
In file included from /usr/include/google/protobuf/stubs/common.h:44,
                 from /usr/include/google/protobuf/io/coded_stream.h:130,
                 from /usr/include/google/protobuf/duration.pb.h:24,
                 from /usr/include/google/protobuf/util/time_util.h:53,
                 from add_person.cc:5:
/usr/include/absl/strings/string_view.h:52:26: error: ‘string_view’ in namespace ‘std’ does not name a type
   52 | using string_view = std::string_view;
      |                          ^~~~~~~~~~~
/usr/include/absl/strings/string_view.h:52:21: note: ‘std::string_view’ is only available from C++17 onwards
   52 | using string_view = std::string_view;
      |                     ^~~
/usr/include/absl/strings/string_view.h:686:8: error: ‘string_view’ does not name a type
  686 | inline string_view ClippedSubstr(string_view s, size_t pos,
      |        ^~~~~~~~~~~
/usr/include/absl/strings/string_view.h:686:8: error: ‘string_view’ does not name a type
  686 | inline string_view ClippedSubstr(string_view s, size_t pos,
      |        ^~~~~~~~~~~
/usr/include/absl/strings/string_view.h:697:11: error: ‘string_view’ does not name a type
  697 | constexpr string_view NullSafeStringView(const char* p) {
      |           ^~~~~~~~~~~
/usr/include/absl/strings/string_view.h:697:11: error: ‘string_view’ does not name a type
  697 | constexpr string_view NullSafeStringView(const char* p) {
      |           ^~~~~~~~~~~
In file included from /usr/include/absl/log/internal/check_op.h:36,
                 from /usr/include/absl/log/internal/check_impl.h:19,
                 from /usr/include/absl/log/absl_check.h:38,
                 from /usr/include/google/protobuf/io/coded_stream.h:132:
/usr/include/absl/log/internal/nullstream.h:49:32: error: ‘absl::string_view’ has not been declared
   49 |   NullStream& AtLocation(absl::string_view, int) { return *this; }
      |                                ^~~~~~~~~~~
In file included from /usr/include/absl/log/internal/check_op.h:36,
                 from /usr/include/absl/log/internal/check_impl.h:19,
                 from /usr/include/absl/log/absl_check.h:38,
                 from /usr/include/google/protobuf/io/coded_stream.h:132:
/usr/include/absl/log/internal/nullstream.h:49:32: error: ‘absl::string_view’ has not been declared
   49 |   NullStream& AtLocation(absl::string_view, int) { return *this; }
      |                                ^~~~~~~~~~~
In file included from /usr/include/absl/time/time.h:89,
                 from /usr/include/absl/log/log_entry.h:35,
                 from /usr/include/absl/log/internal/log_message.h:41,
                 from /usr/include/absl/log/internal/strip.h:24,
                 from /usr/include/absl/log/internal/check_op.h:37:
/usr/include/absl/time/civil_time.h:489:27: error: ‘string_view’ is not a member of ‘absl’
  489 | bool ParseCivilTime(absl::string_view s, CivilSecond* c);
      |                           ^~~~~~~~~~~
/usr/include/absl/time/civil_time.h:489:53: error: expected primary-expression before ‘*’ token
  489 | bool ParseCivilTime(absl::string_view s, CivilSecond* c);
      |                                                     ^
In file included from /usr/include/absl/time/time.h:89,
                 from /usr/include/absl/log/log_entry.h:35,
                 from /usr/include/absl/log/internal/log_message.h:41,
                 from /usr/include/absl/log/internal/strip.h:24,
                 from /usr/include/absl/log/internal/check_op.h:37:
/usr/include/absl/time/civil_time.h:489:27: error: ‘string_view’ is not a member of ‘absl’
  489 | bool ParseCivilTime(absl::string_view s, CivilSecond* c);
      |                           ^~~~~~~~~~~
/usr/include/absl/time/civil_time.h:489:53: error: expected primary-expression before ‘*’ token
  489 | bool ParseCivilTime(absl::string_view s, CivilSecond* c);
      |                                                     ^
/usr/include/absl/time/civil_time.h:489:55: error: ‘c’ was not declared in this scope
  489 | bool ParseCivilTime(absl::string_view s, CivilSecond* c);
      |                                                       ^
/usr/include/absl/time/civil_time.h:489:56: error: expression list treated as compound expression in initializer [-fpermissive]
  489 | bool ParseCivilTime(absl::string_view s, CivilSecond* c);
      |                                                        ^
/usr/include/absl/time/civil_time.h:490:6: error: redefinition of ‘bool absl::lts_20230125::ParseCivilTime’
  490 | bool ParseCivilTime(absl::string_view s, CivilMinute* c);
      |      ^~~~~~~~~~~~~~
/usr/include/absl/time/civil_time.h:489:55: error: ‘c’ was not declared in this scope
  489 | bool ParseCivilTime(absl::string_view s, CivilSecond* c);
      |                                                       ^
/usr/include/absl/time/civil_time.h:489:56: error: expression list treated as compound expression in initializer [-fpermissive]
  489 | bool ParseCivilTime(absl::string_view s, CivilSecond* c);
      |                                                        ^
/usr/include/absl/time/civil_time.h:490:6: error: redefinition of ‘bool absl::lts_20230125::ParseCivilTime’
  490 | bool ParseCivilTime(absl::string_view s, CivilMinute* c);
      |      ^~~~~~~~~~~~~~
/usr/include/absl/time/civil_time.h:489:6: note: ‘bool absl::lts_20230125::ParseCivilTime’ previously defined here
  489 | bool ParseCivilTime(absl::string_view s, CivilSecond* c);
      |      ^~~~~~~~~~~~~~
/usr/include/absl/time/civil_time.h:489:6: note: ‘bool absl::lts_20230125::ParseCivilTime’ previously defined here
  489 | bool ParseCivilTime(absl::string_view s, CivilSecond* c);
      |      ^~~~~~~~~~~~~~
/usr/include/absl/time/civil_time.h:490:27: error: ‘string_view’ is not a member of ‘absl’
  490 | bool ParseCivilTime(absl::string_view s, CivilMinute* c);
      |                           ^~~~~~~~~~~
/usr/include/absl/time/civil_time.h:490:53: error: expected primary-expression before ‘*’ token
  490 | bool ParseCivilTime(absl::string_view s, CivilMinute* c);

After that, I have tried to follow the official install guide to install like this:

bazel build :protoc :protobuf
cp bazel-bin/protoc /usr/local/bin

I don't know if the bazel have install the runtime? Is it an automatical procession? When I do these things, I got same erros above.


Then, I tried to use bazel.
bazel build :add_person_cpp

Everthing works well, and the binary add_person_cpp and list_people_cpp works as well, I have tried to copy them to another machine, and they work, are they need the runtime? Or the runtime is just used for compile.

It's my first question here, if i haved made any mistake, plese inform me, thanks a lot for your answers.

  • 3
    Looks like either your compiler doesn't support string_view or you're compiling with an earlier standard that excludes it. What compiler and version are you using? – Retired Ninja Jul 19 '23 at 04:51
  • @RetiredNinja thanks, here's the version: `g++ (GCC) 13.1.1 20230429`. the error is not only about string_view it's 18869 lines long. – Limpol R Jul 19 '23 at 04:59
  • Generally it would be best to start with the first error and the compile command that generated it. – Retired Ninja Jul 19 '23 at 05:12

1 Answers1

0

Well, After I change the c++ standart in makefile to c++17, it seems work well. And the official cmake do works, now I'm trying to write my own cmake file.

add_person_cpp: add_person.cc protoc_middleman
    pkg-config --cflags protobuf  # fails if protobuf is not installed
    c++ -std=c++17 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++17 list_people.cc addressbook.pb.cc -o list_people_cpp `pkg-config --cflags --libs protobuf`