首页 > 解决方案 > 运行时无法加载由协议缓冲区静态库链接的节点 js 本机插件

问题描述

使用带有 (-fPIC enabled) 的协议缓冲区库 (3.5) 静态库构建节点 js 本机插件 (.node)。

能够构建共享库并能够与可执行文件链接。它在没有运行时协议缓冲区的情况下运行良好。

命令:

g++ -c -fPIC library.cpp //generate object file.
g++ -shared -fPIC -pthread -rdynamic -O3 -o libtest.so library.o  -L . -lcrypto -lssl -lprotobuf //generate so file
g++ -Wall -o main  main.cpp -L . -ltest //built executable. no issue while executing

node js 本机插件中使用的相同协议缓冲区库(3.5)静态库。编译工作正常。js 在运行时加载库失败并抛出错误。

命令:

  g++ -o Release/obj.target/test.node -shared -pthread -rdynamic -m64  -Wl,-soname=test.node -Wl,--start-group Release/obj.target/main.o Release/obj.target/manager.o Release/obj.target/../../../../node_modules/node-addon-api/nothing.a -Wl,--end-group -Wl,--whole-archive ../gcc_5_4/x64/lib/release/libcrypto.a ../gcc_5_4/x64/lib/release/libssl.a ../gcc_5_4/x64/lib/release/libprotobuf.a

在抛出 'google::protobuf::FatalException' 的实例后调用终止 what():该程序需要 3.5.0 版的 Protocol Buffer 运行时库,但安装的版本是 2.6.1。请更新您的图书馆。如果您自己编译程序,请确保您的标头来自与链接时库相同版本的 Protocol Buffers。(“/local/mnt/workspace/src/main/data.pb.cc”中的版本验证失败。) [libprotobuf FATAL google/protobuf/stubs/common.cc:61] 该程序需要 3.5.0 版本的协议缓冲运行时库,但安装的版本是2.6.1。请更新您的图书馆。如果您自己编译程序,请确保您的标头来自与链接时库相同版本的 Protocol Buffers。(版本验证失败在“

你能帮我找出问题的原因吗?

标签: c++node.jsg++ubuntu-16.04

解决方案


推荐阅读