Boost library with node.js addon - segfault - c++

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?

Related

node-gyp build fails on C++ exception handling (warning C4530: C++ exception handler used, but unwind semantics are not enabled.) Want /EHsc

Trying to get node-gyp to build a trivial C++ Hello World program with added xxx() routine that uses try/catch/finally. Says I need to specify /EHsc but have tried and failed at all attempts. If I comment out the finally clause, it warns, builds and runs. With the finally clause in, it fails.
current attempt at binding.gyp:
{
"targets": [
{
"target_name": "greet",
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],
"sources": [
"./src/greeting.cpp",
"./src/index.cpp"
],
"include_dirs": [
"<!#(node -p \"require('node-addon-api').include\")"
],
'conditions': [
['OS=="win"', {
'VCCLCompilerTool': {
"AdditionalOptions": [
"/EHsc",
"/execution-charset:utf-8",
"/source-charset:utf-8",
],
'WarningLevel': 4,
'ExceptionHandling': 1,
},
'defines': [
'WINDOWS_SPECIFIC_DEFINE',
],
}],
],
},
],
'configurations': {
'Release': {
'msvs_settings': {
'VCCLCompilerTool': {
'ExceptionHandling': 1
}
}
}
}
}
#include <string>
#include "greeting.h"
std::string hello( std::string name ) {
return "Hello " + name + "!";
}
void xxx() {
int i=1;
i++;
try {
i++;
}
catch(...){
i = -1;
}
/*
finally {
i = -22;
}
*/
}
Any hints, clues, or otherwise desperately appreciated.
Thanks.
--Tracy

Problem with my Native C++ Addon in Electron in Mac

I am writing code to load c++ dynamic library from electron. When trying it in Mac I get the following error:
dyld: Symbol not found: __ZN15FcDrive2Library13InitDrive2LibEv
Referenced from: /Users/nikhell/Documents/Codelathe/Workspace/cl-fc-client/electron-drive-client/build/Release/electronToCppBridge.node
Expected in: flat namespace
My binding.gyp file looks like this:
{
"targets":[
{
"target_name": "electronToCppBridge",
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],
'include_dirs': [
"<!#(node -p \"require('node-addon-api').include\")"
],
'dependencies': [
"<!(node -p \"require('node-addon-api').gyp\")"
],
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
"copies":[
{
'destination': './node_modules/electron/dist',
'files':[
'../../cl-fc-client/release/support/common/clientca.pem',
'../../cl-fc-client/release/support/common/clientcert.pem',
'../../cl-fc-client/clouddrive2/config.xml',
'../../cl-fc-client/release/support/prebuilt/translationsdc.zip'
]
},
{
'destination': './src',
'files':['../cloudDrive2Lib/LibraryEntry/cloudDrive2Library.h']
}
],
"conditions":[
["OS=='win'",
{
"copies":[
{
'destination': './build/Release',
'files':[
'../../cl-fc-client-thirdparty/bugtrap/BugTrapU-x64.dll',
'../build/bin/msvc/Release64/cloudDrive2Lib.dll',
'../../cl-fc-client-thirdparty/openssl/1.0.2j/lib/x86_64-win32/ssleay32MD.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoZip64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoXML64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoUtil64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoNetSSL64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoNet64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoJSON64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoFoundation64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoCrypto64.dll',
'../../cl-fc-client-thirdparty/openssl/1.0.2j/lib/x86_64-win32/libeay32MD.dll'
]
},
{
'destination': './libs',
'files':['../build/bin/msvc/Release64/cloudDrive2Lib.lib']
},
],
"sources": [
"src/electronToCppBridge.cc",
],
}
],
["OS=='mac'",
{
"copies":[
{
'destination': './build/Release',
'files':[
'../build/bin/darwin/release/libfileclouddrive2lib.dylib',
'../../cl-fc-client-thirdparty/poco/1.7.5/lib/Darwin/x86_64/libPocoCrypto.45.dylib',
'../../cl-fc-client-thirdparty/poco/1.7.5/lib/Darwin/x86_64/libPocoFoundation.45.dylib',
'../../cl-fc-client-thirdparty/poco/1.7.5/lib/Darwin/x86_64/libPocoJSON.45.dylib',
'../../cl-fc-client-thirdparty/poco/1.7.5/lib/Darwin/x86_64/libPocoNet.45.dylib',
'../../cl-fc-client-thirdparty/poco/1.7.5/lib/Darwin/x86_64/libPocoNetSSL.45.dylib'
]
},
{
'destination': './libs',
'files':[
'../build/bin/darwin/release/libfileclouddrive2lib.dylib'
]
},
],
"sources": [
"src/electronToCppBridge.cc",
"libs/libfileclouddrive2lib.dylib",
],
}
]
],
}
]
}
Its working in windows. In Mac I have tried reinstalling the node modules and electron-rebuild also. None of them works for me. Th dylib is getting copied successfully besides the native .node module. Dont know why this link error is coming
Never mind. I realized that the link_dependencies tag needs to be added in binding.gyp. Also the dylib needs to be copied at the root of the project.

binding.gyp: How to use "copies" section to copy files in multiple location

I am writing code to load c++ dll from electron. I am using node-gyp. In my binding.gyp file I use "copies" tag to copy dlls to Release folder. However I want to copy few more files to be copied to a different location. I tried hit and trial method to do it but was unsuccessful. Here is how my binding.gyp looks:
{
"targets": [{
"conditions":[
["OS=='win'", {
"copies":[{
'destination': './build/Release',
'files':[
'../../cl-fc-client-thirdparty/bugtrap/BugTrapU-x64.dll',
'../build/bin/msvc/Release64/cloudDrive2Lib.dll',
'../../cl-fc-client-thirdparty/openssl/1.0.2j/lib/x86_64-win32/ssleay32MD.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoZip64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoXML64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoUtil64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoNetSSL64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoNet64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoJSON64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoFoundation64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoCrypto64.dll',
'../../cl-fc-client-thirdparty/openssl/1.0.2j/lib/x86_64-win32/libeay32MD.dll'
]
}]
}]
],
"target_name": "electronToCppBridge",
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],
"sources": [
"src/electronToCppBridge.cc",
],
'include_dirs': [
"<!#(node -p \"require('node-addon-api').include\")"
],
'libraries': ["../libs/cloudDrive2Lib.lib"],
'dependencies': [
"<!(node -p \"require('node-addon-api').gyp\")"
],
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ]
}]
}
Never mind, I was able to achieve this in the following way:
{
"targets": [{
"conditions":[
["OS=='win'", {
"copies":[
{
'destination': './build/Release',
'files':[
'../../cl-fc-client-thirdparty/bugtrap/BugTrapU-x64.dll',
'../build/bin/msvc/Release64/cloudDrive2Lib.dll',
'../../cl-fc-client-thirdparty/openssl/1.0.2j/lib/x86_64-win32/ssleay32MD.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoZip64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoXML64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoUtil64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoNetSSL64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoNet64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoJSON64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoFoundation64.dll',
'../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoCrypto64.dll',
'../../cl-fc-client-thirdparty/openssl/1.0.2j/lib/x86_64-win32/libeay32MD.dll'
]
},
{
'destination': './libs',
'files':['../build/bin/msvc/Release64/cloudDrive2Lib.lib']
}
]
}]
],
"target_name": "electronToCppBridge",
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],
"sources": [
"src/electronToCppBridge.cc",
],
'include_dirs': [
"<!#(node -p \"require('node-addon-api').include\")"
],
'libraries': ["../libs/cloudDrive2Lib.lib"],
'dependencies': [
"<!(node -p \"require('node-addon-api').gyp\")"
],
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ]
}]
}

How do I add atomic, lm, and lpthread libraries to the binding.gyp file?

I need to add the latomic, lm, lpthread libraries to the binding.gyp in a node-gyp project
I have tried adding the libraries under "libraries" as show below
'targets': [
{
'target_name': 'dut',
'sources': ["<!#(node -p \"require('./getconfig.js').sources\")"],
'include_dirs': ["<!#(node -p \"require('node-addon-api').include\")",
"<!#(node -p \"require('./getconfig.js').libraries\")"
],
'libraries': ["../obj_dir/verilator_global_libs.a",
"../obj_dir/Vtop_elastic__ALL.a",
"-lm",
"-latomic",
"-lstdc++",
"-lpthread"],
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],
'cflags' : [ '-std=c++11' ],
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'CLANG_CXX_LIBRARY': 'libc++',
'MACOSX_DEPLOYMENT_TARGET': '10.7'
},
'msvs_settings': {
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
}
}
]
}
I keep getting this error
error: ‘atomic’ in namespace ‘std’ does not name a template type
std::atomic<bool> m_notified; // Notification pending

using chutzpah and jasmine with typescript and systemjs

I am having trouble getting an import working in a jasmine unit test that is written in typescript. Chutzpah is throwing an error on the import statement - which in js gets translated to a define
import {fakeclass} from '../src/data-analysis/fakeclass';
The error I see is:
Error: ReferenceError: Can't find variable: define
Otherwise the test gets discovered and runs fine.
I assume it has to with systemjs not being loaded by chutzpah - is there a recommended way to set this up?
here is my chutzpah.json file
{
"Framework": "jasmine",
"TestHarnessReferenceMode": "Normal",
"TypeScriptModuleKind": "CommonJS",
"Compile": {
"Mode": "External",
"Extensions": [ ".ts" ],
"ExtensionsWithNoOutput": [ ".d.ts" ]
},
"References": [
{
"Includes": [ "src/*.ts" ],
"Excludes": [ "src/*.d.ts" ]
},
{
"Path": "./jspm_packages/system.src.js",
"IsTestFrameworkFile": true
},
{
"Path": "./jspm_packages/system-polyfills.src.js",
"IsTestFrameworkFile": true
},
{
"Path": "./config.js",
"IsTestFrameworkFile": true
}
],
"Tests": [
{
"Includes": [ "*/test/*.ts" ],
"Excludes": [ "*/test/*.d.ts" ]
}
]}
I took a look at the sample you gave me and got it working by following the pattern in the Chutzpah Angular2 sample.
config.js
System.config({
defaultJSExtensions: true,
transpiler: "babel",
babelOptions: {
"optional": [
"es7.decorators",
"runtime"
]
},
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*"
},
map: {
}
});
chutzpah.json
{
"Framework": "jasmine",
"TestHarnessReferenceMode": "AMD",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"Compile": {
"Mode": "External",
"Extensions": [ ".ts" ],
"ExtensionsWithNoOutput": [ ".d.ts" ]
},
"References": [
{
"Path": "./jspm_packages/system.src.js",
"IsTestFrameworkFile": true
},
{
"Path": "./jspm_packages/system-polyfills.src.js",
"IsTestFrameworkFile": true
},
{
"Path": "./config.js",
"IsTestFrameworkFile": true
}
],
"Tests": [
{
"Includes": [ "*/test/*.ts" ],
"Excludes": [ "*/test/*.d.ts" ]
}
],
"Server": {
"Enabled": true
}
}