I am building a native module that needs to link a static library. The path to that library. My binding.gyp file has the following appearance:
{
"targets": [
{
"target_name": "DcpServer",
"sources": [
"DcpServer.cc"
],
"include_dirs": [
"../../coratools",
"../../../boost-1.65.1"
],
"libraries": [
"<(module_root_dir)/../../coratools/release_uni64/coratools.lib"
],
"defines": [ "CSIWEB_EMBEDDED", "UNICODE", "_UNICODE" ],
"configurations": {
"Release": {
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": 1,
"RuntimeTypeInfo": "true"
}
}
},
"Debug": {
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": 1,
"RuntimeTypeInfo": "true"
}
}
}
}
}
]
}
The path to coratools.lib will vary based upon whether the debug or release configuration is selected. The problem is that node-gyp did not allow me to place the "libraries" key within the "configurations" property. Is there a way of doing what I want by making the library path conditional?
I never did discover how to do this. In the end, I switched to using cmake-js to build my native module.
Related
I am trying to create a Node C++ module for the purpose of interfacing with the Steam api. The library file is ./steam/lib/linux64/libsteam_api.so, and header files are in ./steam.
I have created a small regular C++ file for testing, which successfully uses the Steam api, imported using #include "steam_api.h". I have complied and imported the shared library like this: g++ -L./steam/lib/linux64 -Wl,-rpath=./steam/lib/linux64 -Isteam -lsteam_api main.cpp
binding.gyp:
{
"targets": [ {
"target_name": "steam",
"sources": [ "steam.cpp" ],
"include_dirs": [
"steam",
"<!#(node -p \"require('node-addon-api').include\")"
],
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],
"libraries": [ "./steam/lib/linux64/libsteam_api.so" ]
} ]
}
When I try to compile the Node module using node-gyp, I get g++: error: ./steam/lib/linux64/libsteam_api.so: No such file or directory
How do I correctly import the shared library?
After looking through some examples and a lot of trial and error, I was able to correct binding.gpy:
{
"targets": [ {
"target_name": "steam",
"sources": [ "steam.cpp" ],
"include_dirs": [
"steam",
"<!#(node -p \"require('node-addon-api').include\")"
],
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],
"libraries": [
"-lsteam_api",
"-L../steam/lib/linux64",
"-Wl,-rpath=./steam/lib/linux64"
]
} ]
}
The libraries section needed to include the arguments similar to how they were invoked with g++, except "-L" differed from "-Wl,-rpath=" and the g++ inputs in needing to start one folder level up for some unknown reason.
It looks like node-gyp is changing the current directory as it runs, which invalidates your relative path. Either use an absolute path instead, or do some experimentation to find the new current directory and then use a path relative to that.
Using babel-watch, when debugging through the Chrome inspector, I don't have source maps available.
When running the same code using babel-node, with the same .babelrc, source maps are available.
Here is my .babelrc:
{
"presets": [
["#babel/preset-env", { "targets": { "node": "current" } } ]
],
"sourceMaps": "inline"
}
How do I make source maps available in babel-watch?
I use some files written with Gherkin mode, but they don't have the ".feature" extension. I tried to change some visual code files related to cucumber extension to be able to highlight files that are not .feature but I had no success.
For example:
Workspace settings.json:
{
"folders": [
{
"path": "/home/user/git"
},
{
"path": "/home/user/Documents/scripts"
}
],
"settings": {}
"cucumberautocomplete.steps": [
"*.myext"
],
"cucumberautocomplete.syncfeatures": "*.myext",
"cucumberautocomplete.strictGherkinCompletion": true
}
It worked changing the file /home/user/.config/Code/User/settings.json and adding this config:
"files.associations": {
"*.myext": "feature"
}
{
"editor.renderWhitespace": "all",
"window.titleBarStyle": "custom",
"editor.fontSize": 15,
"python.jediEnabled": false,
"terminal.integrated.shell.linux": "/bin/bash",
"workbench.colorTheme": "Visual Studio Dark",
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"[feature]": {
},
"files.associations": {
"*.myext": "feature"
}
}
I have the following .babelrc.js in the root folder:
{
"plugins": [
"#babel/plugin-transform-flow-strip-types",
"#babel/plugin-transform-modules-commonjs",
"#babel/plugin-transform-async-to-generator",
"#babel/plugin-transform-strict-mode",
"#babel/plugin-transform-runtime"
],
"cache": "true"
}
but when it tries to run node ./packages/jest-cli/bin/jest.js I see:
Caching was left unconfigured. Babel's plugins, presets, and .babelrc.js files can be configured
for various types of caching, using the first param of their handler functions:
What am I missing?
Use new babel.config.js
https://new.babeljs.io/docs/en/next/babelconfigjs.html
module.exports = function(api) {
api.cache(true)
return {
plugins: [
"#babel/plugin-transform-flow-strip-types",
"#babel/plugin-transform-modules-commonjs",
"#babel/plugin-transform-async-to-generator",
"#babel/plugin-transform-strict-mode",
"#babel/plugin-transform-runtime"
]
}
}
After generating a .sln and .vcxproj from the gyp file below msbuild fails with
"C:\proj\test\test.sln" (default target) (1) ->
(ValidateSolutionConfiguration target) ->
C:\proj\test\test.sln.metaproj : error MSB4126: The specified soluti
on configuration "Default|X64" is invalid. Please specify a valid
solution conf iguration using the Configuration and Platform
properties (e.g. MSBuild.exe Sol ution.sln /p:Configuration=Debug
/p:Platform="Any CPU") or leave those properti es blank to use the
default solution configuration. [C:\proj\test\test.sln]
how do I make gyp generate a Default|x64 solution?
{
'targets': [
{
'target_name': 'test',
'type': 'executable',
'sources': [
'test.cpp',
],
},
],
}
Probably you need to have declared target configuration and use it as a default value of target_default, similar to this:
{
'target_defaults': {
'default_configuration': 'Release_x64',
'configurations':
{
'Debug': {
# configuration specific settings
},
'Release': {
# configuration specific settings
},
'Debug_x64': {
'inherit_from': ['Debug'],
'msvs_configuration_platform': 'x64',
},
'Release_x64': {
'inherit_from': ['Release'],
'msvs_configuration_platform': 'x64',
},
},
},
'targets': [
{
'target_name': 'test',
'type': 'executable',
'sources': [
'test.cpp',
],
},
],
}