Protobuf,LD:未找到建筑ARM64的符号

发布于 2025-01-21 15:45:08 字数 10454 浏览 1 评论 0原文

I tried to use protobuf with these steps:

  1. Go to c++ installation page
  2. Install packages brew install autoconf automake libtool
  3. Reinstall Xcode and Command Line Tools from apple developer
  4. Compile protobuf ./autogen.sh && ./configure&&制造-j $(nproc)&&进行检查&& make install
  5. 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:

  1. Go to c++ installation page
  2. Install packages brew install autoconf automake libtool
  3. Reinstall Xcode and Command Line Tools from apple developer
  4. Compile protobuf ./autogen.sh && ./configure && make -j$(nproc) && make check && make install
  5. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏夜暖风 2025-01-28 15:45:08

解决了,我需要添加添加cmakelists.txt

target_link_libraries(try_protobuf ${Protobuf_LIBRARIES})

参见问题

Solved, I needed to add to add CMakeLists.txt

target_link_libraries(try_protobuf ${Protobuf_LIBRARIES})

See the issue

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文