2

package.json:

{
  "name": "BoostRegexJS",
  "version": "0.0.1",
  "description": "Boost::Regex API for node.js",
  "main": "regex.js",
  "private": true,
  "dependencies": {
    "bindings": "~1.2.1",
    "nan": "^2.0.0"
  },
  "scripts": {
    "test": "node regex.js"
  },
  "gypfile": true
}

bindings.gyp

{
    "targets": [
        {
            "target_name": "boostregex",
            "sources": [ "regex.cpp" ],
            "include_dirs": [
                "~/boost/include",
                "<!(node -e \"require('nan')\")"
            ],
            "libraries": [
                "~/boost/lib/libboost_regex.so"
            ],
            "cflags_cc!": [ "-fno-rtti", "-fno-exceptions" ],
            "cflags!": [ "-fno-exceptions" ],
            "conditions": [
                ['OS=="mac"', {
                    "xcode_settings": {
                        'OTHER_CPLUSPLUSFLAGS' : ['-std=c++11','-stdlib=libc++', '-v'],
                        'OTHER_LDFLAGS': ['-stdlib=libc++'],
                        'MACOSX_DEPLOYMENT_TARGET': '10.7',
                        'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
                    }
                }],
                ['OS!="win"', {
                    'include_dirs': [ 'config/win' ],
                    'cflags+': [ '-std=c++11' ],
                    'cflags_c+': [ '-std=c++11' ],
                    'cflags_cc+': [ '-std=c++11' ],
                }]
            ]
        }
    ]
}

regex.cpp

#include <nan.h>

#include <string>
#include <boost/regex.hpp>

void Method(const Nan::FunctionCallbackInfo<v8::Value>& info) {
    info.GetReturnValue().Set(Nan::New("worldd").ToLocalChecked());
}

void Init(v8::Local<v8::Object> exports) {
    exports->Set(Nan::New("hello").ToLocalChecked(), Nan::New<v8::FunctionTemplate>(Method)->GetFunction());
}

NODE_MODULE(boostregex, Init)

Just because #include<boost/regex.hpp> I've got segfault when run this code:

var addon = require('bindings')('boostregex');
console.log(addon.hello()); // 'world'

without this include, addon works fine..

weird because it is just header file..

The Boost libraries compiled succesfully (tried clang and gcc, both ok)

FreeBSD, Node.js v4

Anyidea why segfault?

ElSajko
  • 1,612
  • 3
  • 17
  • 37
  • Are you able to get a stack trace? Also is it possible that the headers are for a different boost version than you are linking to? – harmic Oct 29 '16 at 02:27
  • @harmic: I have only node.core dump file. Headers and libs are generated/copied programatically to same dir, so it is for sure for same version. – ElSajko Oct 29 '16 at 21:51
  • Install gdb, then open the core dump with it. You can print the stack trace (command bt). Might give you a clue – harmic Oct 29 '16 at 21:54
  • @harmic: got it, not opitmistic: (gdb) core node.core Core was generated by `node'. Program terminated with signal 11, Segmentation fault. #0 0x0000000000000000 in ?? () – ElSajko Oct 30 '16 at 14:07

0 Answers0