Monday 8 May 2017

Postgres driver in NodeJS C++ Addon

I'm currently developing a C++ addon for NodeJS using the abstraction layer Nan. I would like to make a postgresql request from this addon. But I get the following error:

   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) 

Here is my binding.gyp:

{
  "targets": [
    {
      "target_name": "MyModule",
      "sources": [ "Main.cpp"],
      "include_dirs": [
        "<!(node -e \"require('nan')\")"
      ],
      "cflags": [
        "-fexceptions",
        "-lpq",
        "-lpqxx"
      ],
      "cflags_cc": [
        "-fexceptions",
        "-lpq",
        "-lpqxx"
      ]
    }
  ]
}

And my Main.cpp file

#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)

I'm stuck with this error and I didn't find any solution on the web. I would be nice if someone could help!

Nomeho



via Nomeho

No comments:

Post a Comment