添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
I have gcc 4.6.3 in my Linux based system. I have successfully built protobuf 3.4.0 from source, used the protoc compiler to actually generate ( .pb.h ) and ( .pb.cc ) using the command:
protoc --cpp_out=. Proto_Schema.proto
Now when I try to compile the C++ code which has included the generated protobuf header, I am getting a large list of error.. why?
Command:g++ -o Check Check.cpp Proto_Schema.pb.cc -lprotobuf -std=c++0x -I/home/protoLib-gcc-4.6.3/build/include/ -L/home/protoLib-gcc-4.6.3/build/lib
Error:
Demo]# g++ -o Check Check.cpp Proto_Schema.pb.cc -lprotobuf -std=c++0x -I/home/protoLib-gcc-4.6.3/build/include/ -L/home/protoLib-gcc-4.6.3/build/lib In file included from /home/protoLib-gcc-4.6.3/build/include/google/protobuf/wire_format_lite_inl.h:44:0, from /home/protoLib-gcc-4.6.3/build/include/google/protobuf/map_type_handler.h:35, from /home/protoLib-gcc-4.6.3/build/include/google/protobuf/map.h:48, from /home/protoLib-gcc-4.6.3/build/include/google/protobuf/generated_message_table_driven.h:34, from Proto_Schema.pb.h:25, from Check.cpp:1: /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:110:21: error: template declaration of ‘google::protobuf::RepeatedField google::protobuf::final’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:111:2: error: expected primary-expression before ‘public’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:111:2: error: expected ‘}’ before ‘public’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:113:31: error: expected ‘)’ before ‘*’ token /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:114:17: error: expected unqualified-id before ‘const’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:114:17: error: expected ‘)’ before ‘const’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:116:22: error: expected ‘)’ before ‘begin’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:117:19: error: expected constructor, destructor, or type conversion before ‘;’ token /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:119:54: error: ‘google::protobuf::RepeatedField& google::protobuf::operator= (const google::protobuf::RepeatedField&)’ must be a nonstatic member function /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:121:16: error: non-member function ‘bool google::protobuf::empty()’ cannot have cv-qualifier /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:122:14: error: non-member function ‘int google::protobuf::size()’ cannot have cv-qualifier /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:124:9: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:125:3: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:127:9: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:128:3: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:130:29: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:130:38: error: ISO C++ forbids declaration of ‘value’ with no type [-fpermissive] /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:131:18: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:131:27: error: ISO C++ forbids declaration of ‘value’ with no type [-fpermissive] /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:134:3: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:142:44: error: ‘Element’ has not been declared /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:155:33: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:155:42: error: ISO C++ forbids declaration of ‘value’ with no type [-fpermissive] /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:159:3: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:160:3: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:161:18: error: non-member function ‘int google::protobuf::Capacity()’ cannot have cv-qualifier /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:166:35: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:166:44: error: ISO C++ forbids declaration of ‘value’ with no type [-fpermissive] /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:170:3: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:171:9: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:187:11: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:188:17: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:189:11: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:190:11: error: ‘value_type’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:191:17: error: ‘value_type’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:192:11: error: ‘value_type’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:193:17: error: ‘value_type’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:197:3: error: ‘iterator’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:198:3: error: ‘const_iterator’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:199:3: error: ‘const_iterator’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:200:3: error: ‘iterator’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:201:3: error: ‘const_iterator’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:202:3: error: ‘const_iterator’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:205:33: error: ‘const_iterator’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:205:47: error: template argument 1 is invalid /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:205:71: error: invalid type in declaration before ‘;’ token /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:206:33: error: ‘iterator’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:206:33: note: suggested alternatives: /home/gcc-4.6.3/build/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/../../../../include/c++/4.6.3/bits/stl_iterator_base_types.h:119:12: note: ‘std::iterator’ /home/gcc-4.6.3/build/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/../../../../include/c++/4.6.3/bits/stl_iterator_base_types.h:119:12: note: ‘std::iterator’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:206:41: error: template argument 1 is invalid /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:206:59: error: invalid type in declaration before ‘;’ token /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h: In function ‘google::protobuf::reverse_iterator google::protobuf::rbegin()’: /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:208:33: error: ‘end’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:208:33: note: suggested alternative: /home/gcc-4.6.3/build/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/../../../../include/c++/4.6.3/initializer_list:96:5: note: ‘std::end’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h: At global scope: /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:210:35: error: non-member function ‘google::protobuf::const_reverse_iterator google::protobuf::rbegin()’ cannot have cv-qualifier /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h: In function ‘google::protobuf::const_reverse_iterator google::protobuf::rbegin()’: /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:210:26: error: redefinition of ‘google::protobuf::const_reverse_iterator google::protobuf::rbegin()’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:207:20: error: ‘google::protobuf::reverse_iterator google::protobuf::rbegin()’ previously defined here /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:211:39: error: ‘end’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:211:39: note: suggested alternative: /home/gcc-4.6.3/build/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/../../../../include/c++/4.6.3/initializer_list:96:5: note: ‘std::end’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h: In function ‘google::protobuf::reverse_iterator google::protobuf::rend()’: /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:214:35: error: ‘begin’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:214:35: note: suggested alternative: /home/gcc-4.6.3/build/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/../../../../include/c++/4.6.3/initializer_list:86:5: note: ‘std::begin’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h: At global scope: /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:216:33: error: non-member function ‘google::protobuf::const_reverse_iterator google::protobuf::rend()’ cannot have cv-qualifier /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h: In function ‘google::protobuf::const_reverse_iterator google::protobuf::rend()’: /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:216:26: error: redefinition of ‘google::protobuf::const_reverse_iterator google::protobuf::rend()’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:213:20: error: ‘google::protobuf::reverse_iterator google::protobuf::rend()’ previously defined here /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:217:41: error: ‘begin’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:217:41: note: suggested alternative: /home/gcc-4.6.3/build/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/../../../../include/c++/4.6.3/initializer_list:86:5: note: ‘std::begin’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h: At global scope: /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:222:39: error: non-member function ‘size_t google::protobuf::SpaceUsedExcludingSelfLong()’ cannot have cv-qualifier /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:224:32: error: non-member function ‘int google::protobuf::SpaceUsedExcludingSelf()’ cannot have cv-qualifier /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:234:3: error: ‘iterator’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:241:3: error: ‘iterator’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:244:41: error: non-member function ‘google::protobuf::Arena* google::protobuf::GetArena()’ cannot have cv-qualifier /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h: In function ‘google::protobuf::Arena* google::protobuf::GetArena()’: /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:245:30: error: ‘GetArenaNoVirtual’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h: At global scope: /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:253:2: error: expected unqualified-id before ‘private’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:269:5: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:275:23: error: uninitialized const ‘google::protobuf::kRepHeaderSize’ [-fpermissive] /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:280:3: error: ‘friend’ used outside of class /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:283:18: error: variable or field ‘MoveArray’ declared void /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:283:18: error: ‘Element’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:283:27: error: ‘to’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:283:31: error: ‘Element’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:283:40: error: ‘from’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:283:46: error: expected primary-expression before ‘int’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:286:18: error: variable or field ‘CopyArray’ declared void /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:286:18: error: ‘Element’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:286:27: error: ‘to’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:286:31: error: expected primary-expression before ‘const’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:286:52: error: expected primary-expression before ‘int’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:289:37: error: non-member function ‘google::protobuf::Arena* google::protobuf::GetArenaNoVirtual()’ cannot have cv-qualifier /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h: In function ‘void google::protobuf::InternalDeallocate(google::protobuf::Rep*, int)’: /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:298:7: error: ‘Element’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:298:16: error: ‘e’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:298:26: error: ‘struct google::protobuf::Rep’ has no member named ‘elements’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:299:16: error: ‘limit’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:299:30: error: ‘struct google::protobuf::Rep’ has no member named ‘elements’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:301:20: error: expected class-name before ‘(’ token /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h: At global scope: /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:314:3: error: ‘friend’ used outside of class /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:314:26: warning: declaration ‘struct google::protobuf::internal::WireFormatLite’ does not declare anything [enabled by default] /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:315:9: error: ‘Element’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:319:27: error: expected initializer before ‘<’ token /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:335:15: error: ‘has_trivial_copy’ was not declared in this scope /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:335:15: note: suggested alternative: /home/protoLib-gcc-4.6.3/build/include/google/protobuf/stubs/type_traits.h:100:27: note: ‘google::protobuf::internal::has_trivial_copy’ /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:335:39: error: expected primary-expression before ‘>’ token /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:335:40: error: ‘value’ in namespace ‘::’ does not name a type /home/protoLib-gcc-4.6.3/build/include/google/protobuf/repeated_field.h:449:22: error: ‘google::internal::enable_if’ has not been declared
What I have tried:
If I am able to properly build the library protobuf using gcc-4.6.3 in my system, why is it showing error when I actually try to work with it?
Check.cpp :
#include " Proto_Schema.pb.h" #include < iostream > int main() { mypackage::MyMessage message; // Define key and value std::string key = " key1" ; std::string value = " value1" ; // Insert the key-value pair into the map using insert method ((message.mutable_my_map())- > insert({key, value })); // Get the value from the map const std::string& retrievedValue = message.my_map().at(key); // Print the retrieved value std::cout < < " Value for key1: " < < retrievedValue < < std::endl ; return 0 ; Proto_Schema.proto: syntax = " proto3" ; package mypackage; message MyMessage { map < string, string= " " > my_map = 1 ; If there is any syntax error in my command or code, kindly let me know. gcc 4.6.3 is about 10 years old, so has no support for c++17 or C++20, which may the issue here. A quick perusal of the Protobuf web site doesn't mention what C++ standard they program to, nor could I find a newsgroup/forum for users. I did find this google group where you may be able to ask your question: Protocol Buffers - Google Groups [ ^ ]
I'd really recommend updating your linux distro, if at all possible to something a little more current, like Ubuntu, Debian, Fedora, Mint, etc, which will include a more recent compiler. Debian 12, for example ships with GCC-12.2. If you're stuck with your current linux distro, you should still be able to compile a newer gcc version. I've successfully compiled gcc-12 on CentOS-6, which ships with gcc-4.4.7. Read the instructions on the GNU gcc web site : Installing GCC- GNU Project [ ^ ] Pay particular attention to the prerequisites: gmp, mpr and mpfr. The default installation location is /usr/local/bin, but you'll need root access to install there. If you do go that root, I highly recommend you use the --program-suffix= option when configuring, so you can distinguish between the distro provided compiler (gcc/g++) and the newer version (gcc-12/g++-12 e.g. with --program-suffix=-12). Be also aware that the newer g++ compiler provides a newer version of libstc++.
Assuming you install in the default location (/usr/local/lib), then you'll also need to do one of the following
* add /usr/local/lib and /usr/local/lib64 to /etc/ld.so.conf, and then run ldconfig (as root). If you do this, then any older programs will also dynamically link to /usr/local/lib versions of libstdc++, and other libs generated by compiling a new version of C++. As far as I'm aware, that's not a problem, but it might be the source of unexpected results in old C++ programs.
* compile with --static-libstdc++. This makes your executables larger, but you won't get undefined symbol references when you try to run your program
* use LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64 myapp: This adds /usr/local/lib and /usr/local/lib64 to the library loader path before the standard library path, so myapp will find the newer versions first. You can add export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64 to your .profile so that you don't have to remember to do it every time.
Also, note that Debian derived systems use a somewhat different path for their dynamic libraries, notably /lib/i386-linux-gnu and /lib/x86_64-linux/gnu, so you you should check with your distro where to find them. That's easily done by writing a quick "Hello World" c++ program, and then using ldd to show you where the files are:
Bash
k5054@ubuntu$ ldd hello linux-vdso.so.1 (0x00007ffce12e1000) libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f88197f4000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f88195cc000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f88194e5000) /lib64/ld-linux-x86-64.so.2 (0x00007f8819a2f000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f88194c5000) k5054@ubuntu$
Finally, if you do install a new version of your compiler, also consider updating binutils and maybe gdb to newer versions too. If you use gdb then note that newer gnu compilers produce dwarf-5 (I think) debug information by default, but older versions of gdb do not know how to deal with it. There are compiler switches to produce older dwarf-3 or dwarf-4 debug info, but it can be annoying to have to remember to either configure your build to use them.
Quote:
I have gcc 4.6.3 in my Linux based system. I have successfully built protobuf 3.4.0 from source, ...

There seem to be quite a few details missing and both "Proto_Schema.proto" and the generated files are missing. I don't have any experience with Protocol Buffers from Google, but I'm surprised that such outdated versions of the gcc compiler and library are used.
Current version of Protocol Buffers is V24.3 from 7.09.2023 ( https://protobuf.dev/ ) and the current gcc version is gcc-13.1.
There are also compiled releases of the Protocol Buffers library at
https://github.com/protocolbuffers/protobuf/releases/latest
Since hardly anyone uses such an old gcc, nor the error generating files are available the search for a solution can be difficult.
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •