我正在嘗試將 x86_64 編譯的 libprotobuf 鏈接到我的 x86_64 可執行檔案。我在 M1 arm64 Macbook Pro 上做這應該無關緊要(交叉編譯)。但我收到一個錯誤。
另一個閉源依賴項是 x86_64,所以我無法在整個專案中執行 arm64
我已經將終端更改arch為i386with arm -x86_64。
我使用以下方法構建了 protobuf x86_64:
cmake -DCMAKE_CXX_STANDARD=17 -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE .. -DCMAKE_INSTALL_PREFIX=<path>/libs/protobuf/mac64 -DCMAKE_OSX_ARCHITECTURES=x86_64
make -j
make install
我得到的庫libprotobuf.a似乎是 x86_64:
objdump -T <path>/libs/protobuf/mac64/lib/libprotobuf.a
....
<path>/lib/libprotobuf.a(common.cc.o): file format mach-o 64-bit x86-64
DYNAMIC SYMBOL TABLE:
<path>/objdump: warning: 'common.cc.o': this operation is not currently supported for this file format
....
所以libprotobuf.a看起來像 x86_64。但是,當鏈接到應用程式時,protobuf 不起作用。這個程序對spdlog圖書館來說是成功的。
#include <iostream>
#include "message.pb.h"
int main() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
return 0;
}
g -std=c 17 -I<path>/protobuf/mac64/include main.cpp -o main -L<path>/libs/protobuf/mac64/lib -lprotobuf
聯結器拋出一個錯誤:
Undefined symbols for architecture x86_64:
"absl::lts_20220623::numbers_internal::FastIntToBuffer(int, char*)", referenced from:
absl::lts_20220623::AlphaNum::AlphaNum(int) in libprotobuf.a(common.cc.o)
"absl::lts_20220623::numbers_internal::FastIntToBuffer(unsigned int, char*)", referenced from:
absl::lts_20220623::AlphaNum::AlphaNum(unsigned int) in libprotobuf.a(common.cc.o)
"absl::lts_20220623::numbers_internal::FastIntToBuffer(long long, char*)", referenced from:
char* absl::lts_20220623::numbers_internal::FastIntToBuffer<long>(long, char*) in libprotobuf.a(common.cc.o)
absl::lts_20220623::AlphaNum::AlphaNum(long long) in libprotobuf.a(common.cc.o)
"absl::lts_20220623::numbers_internal::FastIntToBuffer(unsigned long long, char*)", referenced from:
char* absl::lts_20220623::numbers_internal::FastIntToBuffer<unsigned long>(unsigned long, char*) in libprotobuf.a(common.cc.o)
absl::lts_20220623::AlphaNum::AlphaNum(unsigned long long) in libprotobuf.a(common.cc.o)
"absl::lts_20220623::numbers_internal::SixDigitsToBuffer(double, char*)", referenced from:
absl::lts_20220623::AlphaNum::AlphaNum(double) in libprotobuf.a(common.cc.o)
"absl::lts_20220623::AlphaNum::AlphaNum(absl::lts_20220623::Hex)", referenced from:
google::protobuf::internal::LogMessage::operator<<(void*) in libprotobuf.a(common.cc.o)
"absl::lts_20220623::StrAppend(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, absl::lts_20220623::AlphaNum const&)", referenced from:
google::protobuf::internal::LogMessage::operator<<(absl::lts_20220623::string_view) in libprotobuf.a(common.cc.o)
google::protobuf::internal::LogMessage::operator<<(void*) in libprotobuf.a(common.cc.o)
google::protobuf::internal::LogMessage::operator<<(int) in libprotobuf.a(common.cc.o)
google::protobuf::internal::LogMessage::operator<<(unsigned int) in libprotobuf.a(common.cc.o)
google::protobuf::internal::LogMessage::operator<<(long) in libprotobuf.a(common.cc.o)
google::protobuf::internal::LogMessage::operator<<(unsigned long) in libprotobuf.a(common.cc.o)
google::protobuf::internal::LogMessage::operator<<(double) in libprotobuf.a(common.cc.o)
...
"absl::lts_20220623::Status::ToStringSlow(absl::lts_20220623::StatusToStringMode) const", referenced from:
absl::lts_20220623::Status::ToString(absl::lts_20220623::StatusToStringMode) const in libprotobuf.a(common.cc.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我需要鏈接其他一些庫嗎?或者有什么例子我可以看看嗎?
uj5u.com熱心網友回復:
需要使用release版本。
我使用了一個git clone版本的 protobuf 庫并遇到了這個問題。下載實際發布版本后,它運行良好。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/537566.html
標籤:C 苹果系统协议缓冲区
下一篇:Docker中的C程式:fwrite(3)和write(2)無法在Windows上修改檔案,但在MacOS上不能
