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

888 Views Asked by At

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.

2

There are 2 best solutions below

0
On

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.

3
On

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.