在iOS中编译C++的Protobuf时出现错误:“未定义符号”和“ld:警告:忽略文件”。

3
我有一些C++代码,被一个iOS项目使用。因此,我需要在iOS中为C++代码提供protobuf支持。
我尝试了这个链接:https://developers.google.com/cardboard/develop/ios/protobuf,还有这个gist:https://gist.github.com/eyeplum/ff0b76f70ca5b8d192cac0b52496433d。但是,它们都会出现以下错误:
...
  CXX      google/protobuf/compiler/csharp/csharp_reflection_class.lo
  CXX      google/protobuf/compiler/csharp/csharp_repeated_enum_field.lo
  CXX      google/protobuf/compiler/csharp/csharp_repeated_message_field.lo
  CXX      google/protobuf/compiler/csharp/csharp_repeated_primitive_field.lo
  CXX      google/protobuf/compiler/csharp/csharp_source_generator_base.lo
In file included from google/protobuf/compiler/csharp/csharp_source_generator_base.cc:39:
./google/protobuf/compiler/csharp/csharp_source_generator_base.h:62:25: warning: private field 'descriptor_' is not used [-Wunused-private-field]
  const FileDescriptor* descriptor_;
                        ^
1 warning generated.
  CXX      google/protobuf/compiler/csharp/csharp_wrapper_field.lo
  CXXLD    libprotoc.la
ar: `u' modifier ignored since `D' is the default (see `U')
  CXXLD    protoc
ld: warning: ignoring file ./.libs/libprotobuf.a, building for iOS-armv7 but attempting to link with file built for iOS-armv7
ld: warning: ignoring file /Users/tom/RefCode/protobuf/src/.libs/libprotobuf.a, building for iOS-armv7 but attempting to link with file built for iOS-armv7
ld: warning: ignoring file ./.libs/libprotoc.a, building for iOS-armv7 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
Undefined symbols for architecture armv7:
  "google::protobuf::compiler::objectivec::ObjectiveCGenerator::ObjectiveCGenerator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::objectivec::ObjectiveCGenerator::~ObjectiveCGenerator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::CodeGenerator::~CodeGenerator()", referenced from:
      google::protobuf::compiler::js::Generator::~Generator() in main.o
      google::protobuf::compiler::ruby::Generator::~Generator() in main.o
      google::protobuf::compiler::php::Generator::~Generator() in main.o
  "google::protobuf::compiler::CommandLineInterface::AllowPlugins(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::CommandLineInterface::RegisterGenerator(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, google::protobuf::compiler::CodeGenerator*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::CommandLineInterface::Run(int, char const* const*)", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::CommandLineInterface::CommandLineInterface()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::CommandLineInterface::~CommandLineInterface()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::cpp::CppGenerator::CppGenerator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::cpp::CppGenerator::~CppGenerator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::java::JavaGenerator::JavaGenerator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::java::JavaGenerator::~JavaGenerator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::csharp::Generator::Generator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::csharp::Generator::~Generator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::python::Generator::Generator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::python::Generator::~Generator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "vtable for google::protobuf::compiler::CodeGenerator", referenced from:
      google::protobuf::compiler::CodeGenerator::CodeGenerator() in main.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for google::protobuf::compiler::js::Generator", referenced from:
      google::protobuf::compiler::js::Generator::Generator() in main.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for google::protobuf::compiler::php::Generator", referenced from:
      google::protobuf::compiler::php::Generator::Generator() in main.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for google::protobuf::compiler::ruby::Generator", referenced from:
      google::protobuf::compiler::ruby::Generator::Generator() in main.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [protoc] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

我已经尝试解决问题,但没有任何进展。欢迎提供帮助!


编辑:对于64位版本也存在错误。我也遵循Google的指南 (https://developers.google.com/cardboard/develop/ios/protobuf)。

...
  CXXLD    protoc
ld: warning: ignoring file /Users/tom/RefCode/protobuf/src/.libs/libprotobuf.a, building for iOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
ld: warning: ignoring file ./.libs/libprotobuf.a, building for iOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
ld: warning: ignoring file ./.libs/libprotoc.a, building for iOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
Undefined symbols for architecture arm64:
  "google::protobuf::compiler::objectivec::ObjectiveCGenerator::ObjectiveCGenerator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::objectivec::ObjectiveCGenerator::~ObjectiveCGenerator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::CodeGenerator::~CodeGenerator()", referenced from:
      google::protobuf::compiler::js::Generator::~Generator() in main.o
      google::protobuf::compiler::ruby::Generator::~Generator() in main.o
      google::protobuf::compiler::php::Generator::~Generator() in main.o
  "google::protobuf::compiler::CommandLineInterface::AllowPlugins(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::CommandLineInterface::RegisterGenerator(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, google::protobuf::compiler::CodeGenerator*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::CommandLineInterface::Run(int, char const* const*)", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::CommandLineInterface::CommandLineInterface()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::CommandLineInterface::~CommandLineInterface()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::cpp::CppGenerator::CppGenerator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::cpp::CppGenerator::~CppGenerator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::java::JavaGenerator::JavaGenerator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::java::JavaGenerator::~JavaGenerator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::csharp::Generator::Generator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::csharp::Generator::~Generator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::python::Generator::Generator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "google::protobuf::compiler::python::Generator::~Generator()", referenced from:
      google::protobuf::compiler::ProtobufMain(int, char**) in main.o
  "vtable for google::protobuf::compiler::CodeGenerator", referenced from:
      google::protobuf::compiler::CodeGenerator::CodeGenerator() in main.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for google::protobuf::compiler::js::Generator", referenced from:
      google::protobuf::compiler::js::Generator::Generator() in main.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for google::protobuf::compiler::php::Generator", referenced from:
      google::protobuf::compiler::php::Generator::Generator() in main.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for google::protobuf::compiler::ruby::Generator", referenced from:
      google::protobuf::compiler::ruby::Generator::Generator() in main.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [protoc] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

你在构建哪个目标平台?Armv7 适用于 32 位设备,已经太旧无法使用。你的 protobuf 是通过源代码导入还是使用现成库?如果是现成的库,是否支持 armv7? - Turtleeeeee
让我试一下。 - Turtleeeeee
@Turtleeeeee 或者,我可以禁用 protoc 吗?请参考此问题:https://stackoverflow.com/questions/69335656/how-to-skip-building-protoc-when-compiling-protobuf-from-source-code 谢谢! - ch271828n
顺便说一下,我已经添加了64位错误。@Turtleeeeee - ch271828n
1
好的,我现在看到了。我正在下载组件。结果不会很快出来。你说跳过protoc。我不认为这可能会有效。因为必须有一些潜在的依赖关系,否则它不会显示在官方设置教程中。 - Turtleeeeee
显示剩余3条评论
1个回答

5

1
哈哈。好的,那就这样吧。 - Turtleeeeee

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接