c++xcodelinker-errorsopenninite

dyld: Library not loaded: libNiTE2.dylib....Reason: image not found


The library I am trying to use is NiTE2, I have successfully include & linked OPENNI2 and the libfreenect driver. Here is the error message:

dyld: Library not loaded: libNiTE2.dylib
  Referenced from: /Users/yangwang/Documents/cinder_projects/basic/xcode/build/Debug/basic.app/Contents/MacOS/basic
  Reason: image not found

NOTE: There are quite a few similar questions regarding the same error messages. but none of them helped my case.

A few things I already tried but not working:

All openni2 and libfreenect related dylibs are being found with no problem.

Here are images of my settings:

project hierarchy view

library search path

XCode v: 9.3.1 Mac os v: 10.13.4

----UPDATE-----

I added some Copy Files settings into Build Phase, screenshot here, including everything inside my include and lib folder. This didn't solve my problem ( yet ). Then, after build, I went myapp.app/Contents/MacOS and used ./myapp to run the build. And it magically runs and found all libraries! I don't quite understand why though, hope someone can explain.


Solution

  • libNite2.dylib is linked from the same folder as the basic executable.

    You could use @executable_path, to point to the dylib: this way, double clicking on the file should work.

    It might be possible to change it using installname_tool:

    cd /Users/yangwang/Documents/cinder_projects/basic/xcode/build/Debug/basic.app/Contents/MacOS/

    then

    install_name_tool -change libNiTE2.dylib @executable_path/libNiTE2.dylib basic.

    Fingers crossed this will work when you double click the .app file.

    You may want to add this as an extra step in Xcode post compile to avoid having to type this every time you change something in code. Something along these lines: bare in mind the screenshot is actually from an OpenFrameworks, not Cinder project, but you should have a similar view in XCode (some variables might be different).

    install_name_tool change dylib path post compile

    Another side note: based on your screenshot it looks like OpenNI is linked against from /usr/local/opt/openni2(guessing Homebrew symlink). This will work on your machine, but not on another mac unless you install OpenNI2 via homebrew on it as well (otherwise, if the OpenNI libs are copied to the executable you can consider setting executable relative paths for these too).