Node-gyp Library not loaded: /usr/local/lib/libmtp.9.dylib - c++

I have been attempting to make a nodejs-native-addon which uses libmtp to carry out certain functions. I have been successful in the building the app but the app is throwing Library not loaded: /usr/local/lib/libmtp.9.dylib. Referenced from: /path/build/Debug/nbind.node. Reason: image not found error when I try to run it on another macbook where the libmtp isn't installed.
This is my binding.gyp file:
{
"targets": [
{
"includes": [
"auto.gypi"
],
"sources": [
"src/native/mtp.cc"
],
"link_settings": {
"libraries": [
"-lmtp"
],
},
}
],
"includes": [
"auto-top.gypi"
],
}
I even attempted to include the dylib file in the libraries option
"link_settings": {
"libraries": [
"<(module_root_dir)/src/native/lib/libmtp.9.dylib"
]
}
but the app fails to start with the Library not loaded: /usr/local/lib/libmtp.9.dylib. Referenced from: /path/build/Debug/nbind.node. Reason: image not found error.
Any help will be appreciated.

The error is indicating that the library libmtp.9.dylib cannot be found in the standard library include path /usr/local/lib
Try setting the environment variable LD_LIBRARY_PATH to point to the location where you have the libmtp.9.dylib before running the node.

One solution would be to create a symlink in a known rpath like /usr/local/lib manually to your built library. Not ideal but it may provide a workaround for at least having successful builds in development.
ln -s <absolute_path>/src/native/lib/libmtp.9.dylib /usr/local/lib/libmtp.9.dylib
This allows the binding.gyp file to find the library without it needing to configure an rpath with whatever process is throwing the error. This is easier in my opinion than tracking down the binding.gyp trace.

Related

Build flatpak package from prebuild binaries (mono and gtk-sharp2 project)

I'm trying to pack my application with flatpak and currently I'm stuck:
How do I make shure, that the runtimes are installed on the target system? I need mono, gtk-sharp2, SFML, CSFML. I learned about the basic runtime, but what about my dependencies?
How do I run the application? I tried
[sven#localhost flatpak]$ flatpak-builder --run build net.sourceforge.audiocuesheet.json /app/AudioCuesheetEditor/./AudioCuesheetEditor
bwrap: execvp /app/AudioCuesheetEditor/./AudioCuesheetEditor: No such file or directory
Some more information about the project:
net.sourceforge.audiocuesheet.json:
{
"app-id": "net.sourceforge.audiocuesheet",
"runtime": "org.gnome.Platform",
"runtime-version": "3.26",
"sdk": "org.gnome.Sdk",
"command": "/AudioCuesheetEditor/AudioCuesheetEditor",
"modules": [
{
"name": "AudioCuesheetEditor",
"buildsystem": "simple",
"build-commands": [
"cp -r AudioCuesheetEditor /app/AudioCuesheetEditor",
"chmod +x /app/AudioCuesheetEditor/AudioCuesheetEditor"
],
"sources": [
{
"type": "archive",
"path": "AudioCuesheetEditor-linux-x64-v2.4.2.zip",
"dest": "AudioCuesheetEditor"
}
]
}
]
}
As you can see, the archive has prebuild binaries, which I would like to deploy to the target maschines. I'm new to flatpak and not really shure, if I'm doing right, so maybe some help from you would be perfect.
Thanks
Sven

Can't build a project package using boost/iostream from bazel

I am using https://github.com/nelhage/rules_boost in a bazel project, everything is working fine except when I try to use boost/iostream.
The problem occurs on windows 10, and not on linux. boost/iostream depends on zlib and the file that is downloaded is https://zlib.net/zlib-1.2.11.tar.gz
The error I get is:
ERROR: .../external/net_zlib_zlib/BUILD.bazel:6:1: in cc_library rule #net_zlib_zlib//:zlib: Expected action_config for 'preprocess-assemble' to be configured
ERROR: Analysis of target '.../storage:storage' failed; build abo
rted: Analysis of target '#net_zlib_zlib//:zlib' failed; build aborted
This is the BUILD file:
cc_library(
name = "storage",
srcs = [
"blobstore.cc",
"blobstore.h",
],
hdrs = [
"blobstore.h",
],
deps = [
"#boost//:iostreams",
],
defines = ["BOOST_ALL_NO_LIB"],
)
Does anyone have idea what the problem might be.
This is unfortunately a bug in our MSVC crosstool. What needs to be done is to add the missing action_config and make sure other compilation flags are compatible. Would you mind creating a github issue?

Using node-gyp Predefined Variable PRODUCT_DIR

In binding.gyp I want to set like this:
"libraries": [ "-Wl,-rpath,<working directory>/build/Release/" ]
I am using the following configuration to do the same:
"libraries": [ "-Wl,-rpath,<!(pwd)/build/Release/" ]
This works but the problem with this is that, it would not work on Windows or wherever pwd is not available and also this is not the best option as there is already a predefined variable PRODUCT_DIR available in node-gyp to achieve this. Strangely I am not able to use this variable PRODUCT_DIR.
I tried following options but no luck. error says Library not loaded: #rpath/<lib>.dylib (rpath is not getting set):
"libraries": [ "-Wl,-rpath,>(PRODUCT_DIR)/build/Release/" ]
"libraries": [ "-Wl,-rpath,<(PRODUCT_DIR)/build/Release/" ]
"libraries": [ "-Wl,-rpath,>(PRODUCT_DIR)"]
"libraries": [ "-Wl,-rpath,<(PRODUCT_DIR)"]
When i tried printing by "<!(echo <(PRODUCT_DIR) 1>&2)" it says builddir: command not found. Looks like variable has value builddir.
Shouldn't it print the target directory instead of builddir ? or builddir means something for compiler ?
Am I not using this variable properly or is there any other variable available that I should be using ?
PRODUCT_DIR behaves really weird, I got to say. I avoid it wherever possible. Often by writing external build scripts with plain node.
The reason why you can't "<!(echo <(PRODUCT_DIR) 1>&2)" is that is some kind of special variable to node-gyp.
However you are using the right format, like here...
{
'files': [ '<(PRODUCT_DIR)/libzip.dll' ],
'destination': '<(module_path)'
}
My guess though is that you need to...
"variables": {
"YOUR_DIR: "<(PRODUCT_DIR)/build/Release/"",
"your_libs": "-Wl,-rpath,<(CURRENT_DIR) ]"
}
You know, it's Python, we don't know about :)

node c++ addon / v8 / custom dependency

I am trying to build a node c++ addon on ubuntu using code::blocks. I have build a addon.node shared library that depends on another shared library dep.so . When creating my basid js file with
var addon = require(./addon.node);
it gives
Error: dep.so: cannot open shared object file: No such file or directory
at Error (native)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:367:17)
at require (module.js:386:17)
at repl:1:13
at REPLServer.defaultEval (repl.js:130:27)
at bound (domain.js:254:14)
at REPLServer.runBound [as eval] (domain.js:267:12)
at REPLServer.<anonymous> (repl.js:277:12)
My dep.so file is included while building addon.node and exists in the same build directory as addon.node
running ld addon.node it gives (among other things)
ld: warning: dep.so, needed by addon.node, not found (try using -rpath or -rpath-link)
ld: warning: cannot find entry symbol _start; not setting start address
addon.node: undefined reference to `v8::ObjectTemplate::SetInternalFieldCount(int)'
so, it seems I have two problems:
1) it can't find my own created dep.so library
2) it can't find v8 library (I guess this needs to be build somehow)
Any suggestions how to get this to work?
Cheers, Mike
nbind makes it easy in general to write Node.js bindings for libraries and libui-node is a practical example of using it, to create a cross-platform native UI. Its binding.gyp file shows how to successfully link with a library called libui placed in the root directory of the module (not the build directory).
On Windows:
"libraries": [
"<(module_root_dir)/libui.lib"
]
Linux:
'ldflags': [
'-Wl,-rpath,<(module_root_dir)',
],
"libraries": [
"<(module_root_dir)/libui.so"
]
OS X:
"xcode_settings": {
"OTHER_LDFLAGS": [
"-L<(module_root_dir)",
"-lui",
"-rpath",
"<(module_root_dir)"
]
}

Symbol not found: _libintl_gettext

I am trying to create a NodeJS module using C++ and node-gyp. The package depends on GNU's Gettext library. I am currently using Mac OS X Mountain Lion. I have tried installing the package myself via manual efforts, via Homebrew, and even via Fink.
The program works via Terminal.app and the package compiles. I can use the .node module just fine, except until I use a method in the library that uses gettext. I get the following errors in REPL and then REPL exits.
dyld: lazy symbol binding failed: Symbol not found: _libintl_gettext
Referenced from: /Users/KevinMartin/Dropbox/www/node-locale/build/Release/locale.node
Expected in: dynamic lookup
dyld: Symbol not found: _libintl_gettext
Referenced from: /Users/KevinMartin/Dropbox/www/node-locale/build/Release/locale.node
Expected in: dynamic lookup
Trace/BPT trap: 5
Thanks in advance.
This is probably happening because you are not listing libintl as a library to be dynamically linked. You need to add something like:
{
"targets": [
{
"target_name": "...",
"sources": ["..."],
"libraries": ["/path/to/gettext/lib/libintl.a"]
}
}
to your binding.gyp file. libintl isn't being linked in your app, statically or dynamically, that is why you get the symbol error.
Edit:
You can probably also do something like:
{
"targets": [{
"target_name": "...",
"sources": [
"..."
],
"link_settings": {
"libraries": ["libintl.8.dylib"]
}
}]
}