我正在尝试为Google的cld 3库编译Node.js绑定。完整的代码可以在这里找到:https://github.com/Aschen/node-cld3
Node.js绑定是一个动态链接库:
file build/Release/cld3.node
build/Release/cld3.node: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=4df93d7ba762a9df6befaa072e54febf8d116bd8, with debug_info, not stripped
当我尝试通过Node.js使用该库时,当程序尝试从Protobuf库(由cld 3使用)中检索符号时,我遇到了一个错误:Error: /build/build/Release/cld3.node: undefined symbol: _ZNK6google8protobuf11MessageLite25InitializationErrorStringB5cxx11Ev
如果我在我的电脑(Manjaro)上构建并运行该程序,那么它可以完美地工作,但是当我尝试编译并使用node:20(基于ubuntu)或debian:bookworm时,我会出现错误。
我感觉它与c++11 Dual ABI(也许还有-D_GLIBCXX_USE_CXX11_ABI=0
宏)有关,因为I had to fix an old CMake configuration file是为了从github.com/google/cld3构建示例。
我尝试使用以下Docker镜像(所有镜像都在仓库中可用)复制构建:
Docker manjarolinux/base:20230521(工作):
- g++ 12.2.1
- cmake 3.26.3
- libprotobuf 3.21.12
- Node.js 18.15.0
Docker节点:20(不工作):
- g++ 10.2.1
- cmake 3.18.4
- libprotobuf 3.12.4
- Node.js 20.2.0
Docker debian:bookworm(not working):
- g++ 12.2.0
- cmake 3.25.1
- libprotobuf 3.21.12
- Node.js 18.13.0
这就像除了Manjaro之外,protobuf库中的混乱符号名称在最终的cld3.node
绑定中是不正确的,但我不明白为什么。
编辑:
在编译的cld3.node
绑定上使用ldd
时,我发现了一个不同之处,当它在Debian或Ubuntu映像上编译时,libprotobuf-lite.so
库没有列出
正如@mmomtchev所建议的,我检查了Node.js二进制文件(预构建),libprotobuf-lite.so(预构建)和cld3.node库(构建)的ABI版本,它们似乎都使用c++11 ABI(objdump --demangle -tT /usr/lib/libprotobuf-lite.so | grep abi:
等)
1条答案
按热度按时间hl0ma9xz1#
您的符号与
google::protobuf::MessageLite::InitializationErrorString[abi:cxx11]() const
分离你可以使用这个网站来demangle:http://demangler.com/
显然,应用程序的某些部分是用C++11
std::string
ABI编译的,而其他部分则不是。你的Node.js来自哪里,cld3
来自哪里?如果您使用预构建的二进制文件的一切,这些问题是很难避免在某些情况下。请参阅这些答案:
Undefined reference to google::protobuf::internal::empty_string_[abi:cxx11]
Linking problems due to symbols with abi::cxx11?