【解決方法】protobuf シリアル化ライブラリがサポートする GCC の最小バージョンは何ですか?


私の Linux ベースのシステムには gcc 4.6.3 があります。 protobuf 3.4.0 をソースからビルドすることに成功し、protoc コンパイラーを使用して実際に (.pb.h) そして (.pb.cc) コマンドを使用して:

protoc --cpp_out=. Proto_Schema.proto

ここで、生成された protobuf ヘッダーを含む C++ コードをコンパイルしようとすると、大量のエラーのリストが表示されます。なぜですか?

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

エラー:

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

私が試したこと:

システムで gcc-4.6.3 を使用してライブラリ protobuf を適切にビルドできているのに、実際に操作しようとするとエラーが表示されるのはなぜですか?

Check.cpp:

C++
#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;
}

コマンドまたはコードに構文エラーがある場合は、お知らせください。

解決策 2

gcc 4.6.3 は約 10 年前のものであるため、c++17 または C++20 はサポートされていません。 5月 ここの問題です。 Protobuf の Web サイトをざっと読んでも、どの C++ 標準に基づいてプログラムされているかについては言及されておらず、ユーザー向けのニュースグループやフォーラムも見つかりませんでした。 この Google グループを見つけました。ここで質問できるかもしれません。 プロトコル バッファ – Google グループ[^]

可能であれば、Linux ディストリビューションを、より新しいコンパイラを含む Ubuntu、Debian、Fedora、Mint などのもう少し最新のものに更新することを強くお勧めします。 たとえば、Debian 12 には GCC-12.2 が同梱されています。 現在の Linux ディストリビューションに行き詰まっている場合でも、新しい gcc バージョンをコンパイルできるはずです。 gcc-4.4.7 に同梱されている gcc-12 を CentOS-6 上で正常にコンパイルしました。 GNU gcc Web サイトの手順を読んでください。 GCC-GNU プロジェクトのインストール[^] 前提条件である gmp、mpr、mpfr には特に注意してください。 デフォルトのインストール場所は /usr/local/bin ですが、そこにインストールするには root アクセスが必要です。 そのルートに行く場合は、を使用することを強くお勧めします。 --program-suffix= これにより、ディストリビューションが提供するコンパイラー (gcc/g++) と新しいバージョン (gcc-12/g++-12、例: –program-suffix=-12) を区別できます。 新しい g++ コンパイラーは、新しいバージョンの libstc++ を提供することにも注意してください。

デフォルトの場所 (/usr/local/lib) にインストールすると仮定すると、次のいずれかを行う必要もあります。
* /usr/local/lib および /usr/local/lib64 を /etc/ld.so.conf に追加し、ldconfig を (root として) 実行します。 これを行うと、古いプログラムも libstdc++ の /usr/local/lib バージョン、および新しいバージョンの C++ をコンパイルして生成された他のライブラリに動的にリンクされます。 私の知る限り、これは問題ではありませんが、古い C++ プログラムでは予期しない結果の原因となる可能性があります。
* –static-libstdc++ でコンパイルします。 これにより、実行可能ファイルは大きくなりますが、プログラムを実行しようとしたときに未定義のシンボル参照が取得されることはありません
* LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64 myapp を使用: これにより、/usr/local/lib と /usr/local/lib64 がライブラリ ローダー パスに追加されます 前に 標準ライブラリのパスなので、myapp は最初に新しいバージョンを見つけます。 あなたは付け加えられます export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64 を .profile に追加すると、毎回忘れずに行うことができます。
また、Debian 派生システムは、動的ライブラリ、特に /lib/i386-linux-gnu および /lib/x86_64-linux/gnu に多少異なるパスを使用するため、それらがどこにあるかをディストリビューションに確認する必要があることに注意してください。 これは、簡単な「Hello World」C++ プログラムを作成し、ldd を使用してファイルの場所を表示することで簡単に実行できます。

バッシュ
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$ 

最後に、新しいバージョンのコンパイラをインストールする場合は、binutils と場合によっては gdb も新しいバージョンに更新することも検討してください。 gdb を使用する場合は、新しい gnu コンパイラはデフォルトで dwarf-5 (だと思う) デバッグ情報を生成しますが、古いバージョンの gdb はそれを処理する方法を知らないことに注意してください。 古い dwarf-3 または dwarf-4 のデバッグ情報を生成するコンパイラ スイッチがありますが、それらを使用するようにビルドを設定することを忘れずに行う必要があるのは面倒な場合があります。

解決策 1

引用:

私の Linux ベースのシステムには gcc 4.6.3 があります。 protobuf 3.4.0 をソースから正常にビルドしました。

かなりの詳細が欠落しているようで、「Proto_Schema.proto」と生成されたファイルの両方が欠落しています。 私は Google のプロトコル バッファーを使用した経験はありませんが、gcc コンパイラーとライブラリのこのような古いバージョンが使用されていることに驚きました。

プロトコル バッファーの現在のバージョンは、2023 年 7 月 9 日以降の V24.3 (https://protobuf.dev/)、現在の gcc バージョンは gcc-13.1 です。

プロトコル バッファー ライブラリのコンパイルされたリリースも次の場所にあります。
https://github.com/protocolbuffers/protobuf/releases/latest

このような古い gcc を使用している人はほとんどおらず、エラー生成ファイルも利用できないため、解決策を探すのは困難です。

コメント

タイトルとURLをコピーしました