Error when compiling Protobuf for C++ in iOS: quot;Undefined symbolsquot; and quot;ld: warning: ignoring filequot;(在IOS中编译Protobuf for C++时出错:quot;未定义符号quot;和quot;ld:警告:忽略文件quot;)
问题描述
我有一些iOS项目使用的C++代码。因此,我需要在iOS中拥有对C++代码的协议支持。
我尝试过这个链接:https://developers.google.com/cardboard/develop/ios/protobuf,还有这个要点: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位版本,也会出错。我也遵循谷歌指南(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
推荐答案
哦,我找到答案了!
查看https://github.com/openssl/openssl/issues/10709#issuecomment-589430851和https://github.com/bitcoin/bitcoin/issues/20825#issuecomment-753444519,解决方案非常简单:
brew uninstall binutils
非常有趣的错误消息和解决方案.
这篇关于在IOS中编译Protobuf for C++时出错:";未定义符号";和";ld:警告:忽略文件";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在IOS中编译Protobuf for C++时出错:";未定义符号";和";ld:警告:忽略文件";
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01