我目前正在使用抽象层Nan为NodeJS开发一个C++插件。我想从这个插件发出一个PostgreSQL请求。但是我收到以下错误:
module.js:597
return process.dlopen(module, path._makeLong(filename));
^
Error: ....cpp/build/Release/MyModule.node: undefined symbol: _ZTVN4pqxx14connect_directE
at Error (native)
at Object.Module._extensions..node (module.js:597:18)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (...cpp/test.js:1:77)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
这是我的绑定.gyp:
{
"targets": [
{
"target_name": "MyModule",
"sources": [ "Main.cpp"],
"include_dirs": [
"<!(node -e "require('nan')")"
],
"cflags": [
"-fexceptions",
"-lpq",
"-lpqxx"
],
"cflags_cc": [
"-fexceptions",
"-lpq",
"-lpqxx"
]
}
]
}
和我的主.cpp文件
#include <nan.h>
#include <iostream>
#include <pqxx/pqxx>
using namespace Nan;
using namespace v8;
using namespace std;
using namespace pqxx;
NAN_METHOD(MyModule) {
// Database connection
connection C(
"dbname = ...
user = ...
password = ...
hostaddr = 127.0.0.1
port = 5432");
}
NAN_MODULE_INIT(Init) {
Nan::Set(target, New<String>("MyModule").ToLocalChecked(),
GetFunction(New<FunctionTemplate>(MyModule)).ToLocalChecked());
}
NODE_MODULE(parser, Init)
我遇到了这个错误,在网上找不到任何解决方案。如果有人能帮忙,我会很高兴!
dlopen
尝试加载共享库。但是,此库缺少一个符号,_ZTVN4pqxx14connect_directE。要对其进行解码:
$ c++filt _ZTVN4pqxx14connect_directE`
vtable for pqxx::connect_direct
因此,您需要将库链接到具有此符号的库(插件(。(邮政司机?确保您的构建系统不会延迟链接,并且在运行时出现库ldd your_addon
。如果驱动程序安装到非标准目录,则可以尝试将 LD_LIBRARY_PATH
设置为 ,作为临时解决方案。