charto / nbind

:sparkles: Magical headers that make your C++ library accessible from JavaScript :rocket:
MIT License
1.97k stars 121 forks source link

binding VG on linux #67

Open subwaystation opened 7 years ago

subwaystation commented 7 years ago

Hi,

I have trouble binding the vg lib on linux. Somehow the linking does not work and I don't know why. If I add a wrong library path, then the linker throughs an error, so all the libs are recognized, but not linked against.....

ERROR:

npm run -- node-gyp configure build

> express4@0.0.0 node-gyp /home1/simon/git/genome-graph-visualization
> node-gyp "configure" "build"

make: Entering directory '/home1/simon/git/genome-graph-visualization/build'
  CXX(target) Release/obj.target/nbind/private/cpp/JS_AG.o
../private/cpp/JS_AG.cpp:83:9: warning: "/*" within comment [-Wcomment]
         /*
         ^
../private/cpp/JS_AG.cpp:273:1: warning: "/*" within comment [-Wcomment]
 /*
 ^
In file included from ../private/cpp/../../../genome-graph-visualization/src/vg.hpp:31:0,
                 from ../private/cpp/JS_AG.cpp:7:
../../genome-graph-visualization/include/lru_cache.h:52:10: warning: ‘template<class> class std::auto_ptr’ is deprecated [-Wdeprecated-declarations]
     std::auto_ptr<Impl> impl_;
          ^
In file included from /usr/include/c++/5/memory:81:0,
                 from ../private/cpp/JS_AG.cpp:3:
/usr/include/c++/5/bits/unique_ptr.h:49:28: note: declared here
   template<typename> class auto_ptr;
                            ^
In file included from ../private/cpp/../../../genome-graph-visualization/src/xag.hpp:12:0,
                 from ../private/cpp/JS_AG.cpp:10:
../../genome-graph-visualization/include/xg.hpp: In constructor ‘xg::XG::XG()’:
../../genome-graph-visualization/include/xg.hpp:265:10: warning: ‘xg::XG::end_marker’ will be initialized after [-Wreorder]
     char end_marker;
          ^
../../genome-graph-visualization/include/xg.hpp:90:12: warning:   ‘size_t xg::XG::seq_length’ [-Wreorder]
     size_t seq_length;
            ^
../../genome-graph-visualization/include/xg.hpp:54:5: warning:   when initialized here [-Wreorder]
     XG(void) : start_marker('#'),
     ^
../private/cpp/JS_AG.cpp: In function ‘std::shared_ptr<vg::AG> getSubgraphFromXagByRange(vg::AG&, vg::XAG&, std::__cxx11::string, std::__cxx11::string, std::__cxx11::string, bool, bool, bool)’:
../private/cpp/JS_AG.cpp:213:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (size_t i = 0; i < ptr_ag->graph.node_size(); ++i) {
                          ^
../private/cpp/JS_AG.cpp: In function ‘void graphToJsonOut(vg::AG*, std::__cxx11::string)’:
../private/cpp/JS_AG.cpp:360:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (size_t idx = 0; idx < ag->graph.path_size(); ++idx) {
                              ^
  CXX(target) Release/obj.target/nbind/node_modules/nbind/src/common.o
  CXX(target) Release/obj.target/nbind/node_modules/nbind/src/reflect.o
  CXX(target) Release/obj.target/nbind/node_modules/nbind/src/v8/Buffer.o
  CXX(target) Release/obj.target/nbind/node_modules/nbind/src/v8/Binding.o
  SOLINK_MODULE(target) Release/obj.target/nbind.node
  COPY Release/nbind.node
make: Leaving directory '/home1/simon/git/genome-graph-visualization/build'
simon@osa0:~/git/genome-graph-visualization$ node app.js 
module.js:598
  return process.dlopen(module, path._makeLong(filename));
                 ^

Error: /home1/simon/git/genome-graph-visualization/build/Release/nbind.node: undefined symbol: _ZN4sdsl4bits6lt_selE
    at Object.Module._extensions..node (module.js:598:18)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at initNode (/home1/simon/git/genome-graph-visualization/node_modules/nbind/dist/nbind.js:140:15)
    at /home1/simon/git/genome-graph-visualization/node_modules/nbind/dist/nbind.js:114:13
    at findCompiledModule (/home1/simon/git/genome-graph-visualization/node_modules/nbind/dist/nbind.js:78:13)
    at find (/home1/simon/git/genome-graph-visualization/node_modules/nbind/dist/nbind.js:92:13)
    at Object.init (/home1/simon/git/genome-graph-visualization/node_modules/nbind/dist/nbind.js:103:5)
    at Object.<anonymous> (/home1/simon/git/genome-graph-visualization/private/javascripts/ag.js:2:17)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home1/simon/git/genome-graph-visualization/private/javascripts/data_set_supervisor.js:8:13)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)

The binding.gyp:

{
  "make_global_settings": [
    ["CXX",  "../node_modules/nbind/bin/g++"],
    ["LINK", "../node_modules/nbind/bin/g++"]
  ],
  "targets": [
    {
      "includes": [
        "auto.gypi"
      ],
      "sources": [
        "private/cpp/JS_AG.cpp"
        #               ,"cpp/JS_VG.cpp"
      ],
      "conditions": [
        ["OS=='mac'", {
          "xcode_settings": {
            "OTHER_CPLUSPLUSFLAGS": [
              "-c",
              "-msse4.1",
              "-fopenmp",
              "-frtti",
              "-ggdb",
              #                            "-o cpp/JS_AG",
              #                            "-Wall",
              #                            "-pedantic",
              "-g",
              "-I../../genome-graph/",
              "-I../../genome-graph/include"
            ],
            "OTHER_LDFLAGS": [
              "-msse4.1",
              "-fopenmp",
              "-ggdb",
              #                            "-Wall",
              #                            "-pedantic",
              "-g",
              "-I../../genome-graph/",
              "-I../../genome-graph/include",
              "-lvg",
              "-lsdsl",
              "-lxg",
              "-lvcflib",
              "-lgssw",
              "-lrocksdb",
              "-lhts",
              "-lgcsa2",
              "-lprotobuf",
              "-lraptor2",
              "-lgfakluge",
              "-lsupbub",
              "-lpinchesandcacti",
              "-l3edgeconnected",
              "-lsonlib",
              "-lm",
              "-lpthread",
              "-ly",
              "-lbz2",
              "-lsnappy",
              "-ldivsufsort",
              "-ldivsufsort64",
              "-ljansson",
              "-lgff",
              "-L../../genome-graph/src",
              "-L../../genome-graph/lib"
            ]
          }
        }],
        ["OS=='linux'", {
          "cflags_cc+": [
            "-c",
            "-msse4.1",
            "-fopenmp",
            "-frtti",
            "-ggdb",
            "-g",
            "-I../../genome-graph/",
            "-I../../genome-graph/include"
          ],
          "link_settings": {
            "ldflags": [
              "-msse4.1",
              "-fopenmp",
              "-ggdb",
              "-g",
              "-I../../genome-graph/",
              "-I../../genome-graph/include",
              "-lvg",
              "-lsdsl",
              "-lxg",
              "-lvcflib",
              "-lgssw",
              "-lrocksdb",
              "-lhts",
              "-lgcsa2",
              "-lprotobuf",
              "-lraptor2",
              "-lgfakluge",
              "-lsupbub",
              "-lpinchesandcacti",
              "-l3edgeconnected",
              "-lsonlib",
              "-lm",
              "-lpthread",
              "-ly",
              "-lbz2",
              "-lsnappy",
              "-ldivsufsort",
              "-ldivsufsort64",
              "-ljansson",
              "-lgff",
              "-L../../genome-graph/src",
              "-L../../genome-graph/lib"
            ]
          }

        }]
      ]
    }
  ],
  "includes": [
    "auto-top.gypi"
  ]
}

Any help would be highly appreciated.

JasurN commented 6 years ago

Hello! Have you found solution for this problem?

JasurN commented 6 years ago

Somehow solved this problem with shared libraries, but for another library. using this tutorial Did it like this. Additionally added "libraries": [ "/home/jasurn/CLionProjects/SecondC/libSome.so" ], into nbind.gyp file(location './node_modules/nbind/srt').

ISNIT0 commented 5 years ago

I'm having this same issue, things look okay when using Debian Jessie, but break on Stretch 😢

ISNIT0 commented 5 years ago

I fixed my issue by adding 'cflags': [ '-D_GLIBCXX_USE_CXX11_ABI=0' ], to my build target.

Seemed the library was adding [abi:cxx11] to my symbols. I don't know enough to understand why! Hopefully this will help someone else.

subwaystation commented 5 years ago

@ISNIT0 Would it make sense to integrate your solution as an optional fix into the tutorial? So I would enhance it ;)

ISNIT0 commented 5 years ago

@subwaystation Go for it :)