I met some problem while using node-gyp to build my C++ code. I would like to include some directories that contain *.h file in sub-directory, but it always shows error No such file or directory. Does anyone who have experience with node-gyp can give me some advice.
Here is my directory structure
----libraries
----library
----modules.h // define a_module.h in modules.h
----a_module.h
----a_module.cpp
----src
----main.h
----binding.gyp
----addon.cc
and my binding.gyp file is below:
{
"targets": [
{
"target_name": "addon",
"sources": [
"addon.cc",
"./libraries/src/main.cpp"
],
"include_dirs": [
],
"dependencies": [
"libs"
]
},
{
"target_name": "libs",
"type": "<(library)",
"include_dirs": [
"./libraries/libraru/",
]
}
]
}
I also try the config below:
{
"targets": [
{
"target_name": "addon",
"sources": [
"addon.cc",
"./libraries/src/main.cpp"
],
"include_dirs": [
"./libraries/library/"
]
}
]
}
I try to call my program with the following path: main.cc -> main.h -> modules.h -> a_module.h -> a_module.cpp.
codes in main.cc
#include "./libraries/src/main.h"
codes in main.h
#include "library/modules.h" // <- No such file or directory error occurred
Is there anything wrong in my binding.gyp file?
Thanks for viewing my question.
Related
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.
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' ]
}]
}
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
I want to access DLL in my node addon. I configured my binding.gyp like this:
{
"variables": {
"dll_files": [
"AUDIOPRO.DLL",
"AUDIOSEA.DLL",
"AUDIOSWA.DLL",
]
},
"targets": [
{
"target_name": "addon",
"sources": [
"Main.cpp"
],
"libraries": [
]
}
]
}
I tried like this in Main.cpp:
const char* processAddress = "../AUDIOPRO.DLL";
HMODULE processModule = LoadLibrary(processAddress);
if (processModule == NULL) {
// always enters here
}
The problem is that processModule is always be NULL, I don't know why....
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?