Protobuf,LD:未找到建筑ARM64的符号
I tried to use protobuf with these steps:
- Go to c++ installation page
- Install packages
brew install autoconf automake libtool
- Reinstall Xcode and Command Line Tools from apple developer
- Compile protobuf
./autogen.sh && ./configure&&制造-j $(nproc)&&进行检查&& make install
- Run the code
CMakeLists.txt:
cmake_minimum_required(VERSION 3.21)
project(try_protobuf)
set(CMAKE_CXX_STANDARD 14)
find_package(Protobuf REQUIRED)
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS position.proto)
add_executable(try_protobuf main.cpp ${PROTO_SRCS} ${PROTO_HDRS})
position.proto
syntax = "proto3";
message Position {
uint32 lat = 1;
uint32 lng = 2;
uint32 alt = 3;
}
main.cpp
#include "position.pb.h"
int main(int argc, char* argv[]) {
return 0;
}
Cmake worked
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/Applications/CLion.app/Contents/bin/ninja/mac/ninja -G Ninja /Users/furkanguvenc/CLionProjects/try-protobuf
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/furkanguvenc/CLionProjects/try-protobuf/cmake-build-debug
[Finished]
But when I executed the code it throws ld: symbol(s) not found for architecture arm64
error
===================[ Build | try_protobuf | Debug ]============================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/furkanguvenc/CLionProjects/try-protobuf/cmake-build-debug --target try_protobuf
[1/1] Linking CXX executable try_protobuf
FAILED: try_protobuf
: && /Users/furkanguvenc/Downloads/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -arch arm64 -isysroot /Users/furkanguvenc/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/try_protobuf.dir/main.cpp.o CMakeFiles/try_protobuf.dir/position.pb.cc.o -o try_protobuf && :
Undefined symbols for architecture arm64:
"google::protobuf::UnknownFieldSet::ClearFallback()", referenced from:
google::protobuf::UnknownFieldSet::Clear() in position.pb.cc.o
"google::protobuf::UnknownFieldSet::default_instance()", referenced from:
Position::_InternalSerialize(unsigned char*, google::protobuf::io::EpsCopyOutputStream*) const in position.pb.cc.o
"google::protobuf::UnknownFieldSet::MergeFrom(google::protobuf::UnknownFieldSet const&)", referenced from:
void google::protobuf::internal::InternalMetadata::DoMergeFrom<google::protobuf::UnknownFieldSet>(google::protobuf::UnknownFieldSet const&) in position.pb.cc.o
"google::protobuf::io::EpsCopyOutputStream::EnsureSpaceFallback(unsigned char*)", referenced from:
google::protobuf::io::EpsCopyOutputStream::EnsureSpace(unsigned char*) in position.pb.cc.o
"google::protobuf::Arena::AllocateAlignedWithHook(unsigned long, std::type_info const*)", referenced from:
google::protobuf::Arena::AllocateAlignedWithHook(unsigned long, unsigned long, std::type_info const*) in position.pb.cc.o
"google::protobuf::Arena::AllocateAlignedWithCleanup(unsigned long, std::type_info const*)", referenced from:
google::protobuf::Arena::AllocateInternal(unsigned long, unsigned long, void (*)(void*), std::type_info const*) in position.pb.cc.o
"google::protobuf::Message::CopyWithSizeCheck(google::protobuf::Message*, google::protobuf::Message const&)", referenced from:
Position::_class_data_ in position.pb.cc.o
"google::protobuf::Message::CheckTypeAndMergeFrom(google::protobuf::MessageLite const&)", referenced from:
vtable for Position in position.pb.cc.o
"google::protobuf::Message::CopyFrom(google::protobuf::Message const&)", referenced from:
vtable for Position in position.pb.cc.o
"google::protobuf::Message::MergeFrom(google::protobuf::Message const&)", referenced from:
vtable for Position in position.pb.cc.o
"google::protobuf::internal::LogMessage::LogMessage(google::protobuf::LogLevel, char const*, int)", referenced from:
Position::SharedDtor() in position.pb.cc.o
Position::MergeFrom(Position const&) in position.pb.cc.o
google::protobuf::internal::InternalMetadata::InternalMetadata(google::protobuf::Arena*, bool) in position.pb.cc.o
google::protobuf::internal::EpsCopyInputStream::DoneWithCheck(char const**, int) in position.pb.cc.o
"google::protobuf::internal::LogMessage::~LogMessage()", referenced from:
Position::SharedDtor() in position.pb.cc.o
Position::MergeFrom(Position const&) in position.pb.cc.o
google::protobuf::internal::InternalMetadata::InternalMetadata(google::protobuf::Arena*, bool) in position.pb.cc.o
google::protobuf::internal::EpsCopyInputStream::DoneWithCheck(char const**, int) in position.pb.cc.o
"google::protobuf::internal::LogMessage::operator<<(char const*)", referenced from:
Position::SharedDtor() in position.pb.cc.o
Position::MergeFrom(Position const&) in position.pb.cc.o
google::protobuf::internal::InternalMetadata::InternalMetadata(google::protobuf::Arena*, bool) in position.pb.cc.o
google::protobuf::internal::EpsCopyInputStream::DoneWithCheck(char const**, int) in position.pb.cc.o
"google::protobuf::internal::WireFormat::InternalSerializeUnknownFieldsToArray(google::protobuf::UnknownFieldSet const&, unsigned char*, google::protobuf::io::EpsCopyOutputStream*)", referenced from:
Position::_InternalSerialize(unsigned char*, google::protobuf::io::EpsCopyOutputStream*) const in position.pb.cc.o
"google::protobuf::internal::LogFinisher::operator=(google::protobuf::internal::LogMessage&)", referenced from:
Position::SharedDtor() in position.pb.cc.o
Position::MergeFrom(Position const&) in position.pb.cc.o
google::protobuf::internal::InternalMetadata::InternalMetadata(google::protobuf::Arena*, bool) in position.pb.cc.o
google::protobuf::internal::EpsCopyInputStream::DoneWithCheck(char const**, int) in position.pb.cc.o
"google::protobuf::internal::ReadTagFallback(char const*, unsigned int)", referenced from:
google::protobuf::internal::ReadTag(char const*, unsigned int*, unsigned int) in position.pb.cc.o
"google::protobuf::internal::ThreadSafeArena::~ThreadSafeArena()", referenced from:
google::protobuf::Arena::~Arena() in position.pb.cc.o
"google::protobuf::internal::AssignDescriptors(google::protobuf::internal::DescriptorTable const* (*)(), std::__1::once_flag*, google::protobuf::Metadata const&)", referenced from:
Position::GetMetadata() const in position.pb.cc.o
"google::protobuf::internal::UnknownFieldParse(unsigned long long, google::protobuf::UnknownFieldSet*, char const*, google::protobuf::internal::ParseContext*)", referenced from:
Position::_InternalParse(char const*, google::protobuf::internal::ParseContext*) in position.pb.cc.o
"google::protobuf::internal::VarintParseSlow32(char const*, unsigned int)", referenced from:
google::protobuf::internal::VarintParseSlow(char const*, unsigned int, unsigned int*) in position.pb.cc.o
"google::protobuf::internal::EpsCopyInputStream::DoneFallback(int, int)", referenced from:
google::protobuf::internal::EpsCopyInputStream::DoneWithCheck(char const**, int) in position.pb.cc.o
"google::protobuf::internal::AddDescriptorsRunner::AddDescriptorsRunner(google::protobuf::internal::DescriptorTable const*)", referenced from:
___cxx_global_var_init in position.pb.cc.o
"google::protobuf::Message::GetTypeName() const", referenced from:
vtable for Position in position.pb.cc.o
"google::protobuf::Message::SpaceUsedLong() const", referenced from:
vtable for Position in position.pb.cc.o
"google::protobuf::Message::InitializationErrorString() const", referenced from:
vtable for Position in position.pb.cc.o
"google::protobuf::Message::MaybeComputeUnknownFieldsSize(unsigned long, google::protobuf::internal::CachedSize*) const", referenced from:
Position::ByteSizeLong() const in position.pb.cc.o
"typeinfo for google::protobuf::Message", referenced from:
typeinfo for Position in position.pb.cc.o
"vtable for google::protobuf::MessageLite", referenced from:
google::protobuf::MessageLite::MessageLite(google::protobuf::Arena*, bool) in position.pb.cc.o
google::protobuf::MessageLite::~MessageLite() in position.pb.cc.o
google::protobuf::MessageLite::MessageLite() in position.pb.cc.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for google::protobuf::Message", referenced from:
google::protobuf::Message::Message(google::protobuf::Arena*, bool) in position.pb.cc.o
google::protobuf::Message::Message() in position.pb.cc.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)
ninja: build stopped: subcommand failed.
OS: Mac M1, Monterey 12.3.1
Clang:
$ clang -v
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Users/furkanguvenc/Downloads/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Command Line Tools:
$ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 13.3.1.0.1.1648687083
volume: /
location: /
install-time: 1649788653
groups: com.apple.FindSystemFiles.pkg-group
I tried to use protobuf with these steps:
- Go to c++ installation page
- Install packages
brew install autoconf automake libtool
- Reinstall Xcode and Command Line Tools from apple developer
- Compile protobuf
./autogen.sh && ./configure && make -j$(nproc) && make check && make install
- Run the code
CMakeLists.txt:
cmake_minimum_required(VERSION 3.21)
project(try_protobuf)
set(CMAKE_CXX_STANDARD 14)
find_package(Protobuf REQUIRED)
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS position.proto)
add_executable(try_protobuf main.cpp ${PROTO_SRCS} ${PROTO_HDRS})
position.proto
syntax = "proto3";
message Position {
uint32 lat = 1;
uint32 lng = 2;
uint32 alt = 3;
}
main.cpp
#include "position.pb.h"
int main(int argc, char* argv[]) {
return 0;
}
Cmake worked
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/Applications/CLion.app/Contents/bin/ninja/mac/ninja -G Ninja /Users/furkanguvenc/CLionProjects/try-protobuf
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/furkanguvenc/CLionProjects/try-protobuf/cmake-build-debug
[Finished]
But when I executed the code it throws ld: symbol(s) not found for architecture arm64
error
===================[ Build | try_protobuf | Debug ]============================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/furkanguvenc/CLionProjects/try-protobuf/cmake-build-debug --target try_protobuf
[1/1] Linking CXX executable try_protobuf
FAILED: try_protobuf
: && /Users/furkanguvenc/Downloads/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -arch arm64 -isysroot /Users/furkanguvenc/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/try_protobuf.dir/main.cpp.o CMakeFiles/try_protobuf.dir/position.pb.cc.o -o try_protobuf && :
Undefined symbols for architecture arm64:
"google::protobuf::UnknownFieldSet::ClearFallback()", referenced from:
google::protobuf::UnknownFieldSet::Clear() in position.pb.cc.o
"google::protobuf::UnknownFieldSet::default_instance()", referenced from:
Position::_InternalSerialize(unsigned char*, google::protobuf::io::EpsCopyOutputStream*) const in position.pb.cc.o
"google::protobuf::UnknownFieldSet::MergeFrom(google::protobuf::UnknownFieldSet const&)", referenced from:
void google::protobuf::internal::InternalMetadata::DoMergeFrom<google::protobuf::UnknownFieldSet>(google::protobuf::UnknownFieldSet const&) in position.pb.cc.o
"google::protobuf::io::EpsCopyOutputStream::EnsureSpaceFallback(unsigned char*)", referenced from:
google::protobuf::io::EpsCopyOutputStream::EnsureSpace(unsigned char*) in position.pb.cc.o
"google::protobuf::Arena::AllocateAlignedWithHook(unsigned long, std::type_info const*)", referenced from:
google::protobuf::Arena::AllocateAlignedWithHook(unsigned long, unsigned long, std::type_info const*) in position.pb.cc.o
"google::protobuf::Arena::AllocateAlignedWithCleanup(unsigned long, std::type_info const*)", referenced from:
google::protobuf::Arena::AllocateInternal(unsigned long, unsigned long, void (*)(void*), std::type_info const*) in position.pb.cc.o
"google::protobuf::Message::CopyWithSizeCheck(google::protobuf::Message*, google::protobuf::Message const&)", referenced from:
Position::_class_data_ in position.pb.cc.o
"google::protobuf::Message::CheckTypeAndMergeFrom(google::protobuf::MessageLite const&)", referenced from:
vtable for Position in position.pb.cc.o
"google::protobuf::Message::CopyFrom(google::protobuf::Message const&)", referenced from:
vtable for Position in position.pb.cc.o
"google::protobuf::Message::MergeFrom(google::protobuf::Message const&)", referenced from:
vtable for Position in position.pb.cc.o
"google::protobuf::internal::LogMessage::LogMessage(google::protobuf::LogLevel, char const*, int)", referenced from:
Position::SharedDtor() in position.pb.cc.o
Position::MergeFrom(Position const&) in position.pb.cc.o
google::protobuf::internal::InternalMetadata::InternalMetadata(google::protobuf::Arena*, bool) in position.pb.cc.o
google::protobuf::internal::EpsCopyInputStream::DoneWithCheck(char const**, int) in position.pb.cc.o
"google::protobuf::internal::LogMessage::~LogMessage()", referenced from:
Position::SharedDtor() in position.pb.cc.o
Position::MergeFrom(Position const&) in position.pb.cc.o
google::protobuf::internal::InternalMetadata::InternalMetadata(google::protobuf::Arena*, bool) in position.pb.cc.o
google::protobuf::internal::EpsCopyInputStream::DoneWithCheck(char const**, int) in position.pb.cc.o
"google::protobuf::internal::LogMessage::operator<<(char const*)", referenced from:
Position::SharedDtor() in position.pb.cc.o
Position::MergeFrom(Position const&) in position.pb.cc.o
google::protobuf::internal::InternalMetadata::InternalMetadata(google::protobuf::Arena*, bool) in position.pb.cc.o
google::protobuf::internal::EpsCopyInputStream::DoneWithCheck(char const**, int) in position.pb.cc.o
"google::protobuf::internal::WireFormat::InternalSerializeUnknownFieldsToArray(google::protobuf::UnknownFieldSet const&, unsigned char*, google::protobuf::io::EpsCopyOutputStream*)", referenced from:
Position::_InternalSerialize(unsigned char*, google::protobuf::io::EpsCopyOutputStream*) const in position.pb.cc.o
"google::protobuf::internal::LogFinisher::operator=(google::protobuf::internal::LogMessage&)", referenced from:
Position::SharedDtor() in position.pb.cc.o
Position::MergeFrom(Position const&) in position.pb.cc.o
google::protobuf::internal::InternalMetadata::InternalMetadata(google::protobuf::Arena*, bool) in position.pb.cc.o
google::protobuf::internal::EpsCopyInputStream::DoneWithCheck(char const**, int) in position.pb.cc.o
"google::protobuf::internal::ReadTagFallback(char const*, unsigned int)", referenced from:
google::protobuf::internal::ReadTag(char const*, unsigned int*, unsigned int) in position.pb.cc.o
"google::protobuf::internal::ThreadSafeArena::~ThreadSafeArena()", referenced from:
google::protobuf::Arena::~Arena() in position.pb.cc.o
"google::protobuf::internal::AssignDescriptors(google::protobuf::internal::DescriptorTable const* (*)(), std::__1::once_flag*, google::protobuf::Metadata const&)", referenced from:
Position::GetMetadata() const in position.pb.cc.o
"google::protobuf::internal::UnknownFieldParse(unsigned long long, google::protobuf::UnknownFieldSet*, char const*, google::protobuf::internal::ParseContext*)", referenced from:
Position::_InternalParse(char const*, google::protobuf::internal::ParseContext*) in position.pb.cc.o
"google::protobuf::internal::VarintParseSlow32(char const*, unsigned int)", referenced from:
google::protobuf::internal::VarintParseSlow(char const*, unsigned int, unsigned int*) in position.pb.cc.o
"google::protobuf::internal::EpsCopyInputStream::DoneFallback(int, int)", referenced from:
google::protobuf::internal::EpsCopyInputStream::DoneWithCheck(char const**, int) in position.pb.cc.o
"google::protobuf::internal::AddDescriptorsRunner::AddDescriptorsRunner(google::protobuf::internal::DescriptorTable const*)", referenced from:
___cxx_global_var_init in position.pb.cc.o
"google::protobuf::Message::GetTypeName() const", referenced from:
vtable for Position in position.pb.cc.o
"google::protobuf::Message::SpaceUsedLong() const", referenced from:
vtable for Position in position.pb.cc.o
"google::protobuf::Message::InitializationErrorString() const", referenced from:
vtable for Position in position.pb.cc.o
"google::protobuf::Message::MaybeComputeUnknownFieldsSize(unsigned long, google::protobuf::internal::CachedSize*) const", referenced from:
Position::ByteSizeLong() const in position.pb.cc.o
"typeinfo for google::protobuf::Message", referenced from:
typeinfo for Position in position.pb.cc.o
"vtable for google::protobuf::MessageLite", referenced from:
google::protobuf::MessageLite::MessageLite(google::protobuf::Arena*, bool) in position.pb.cc.o
google::protobuf::MessageLite::~MessageLite() in position.pb.cc.o
google::protobuf::MessageLite::MessageLite() in position.pb.cc.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for google::protobuf::Message", referenced from:
google::protobuf::Message::Message(google::protobuf::Arena*, bool) in position.pb.cc.o
google::protobuf::Message::Message() in position.pb.cc.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)
ninja: build stopped: subcommand failed.
OS: Mac M1, Monterey 12.3.1
Clang:
$ clang -v
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Users/furkanguvenc/Downloads/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Command Line Tools:
$ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 13.3.1.0.1.1648687083
volume: /
location: /
install-time: 1649788653
groups: com.apple.FindSystemFiles.pkg-group
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了,我需要添加添加cmakelists.txt
参见问题
Solved, I needed to add to add CMakeLists.txt
See the issue