0

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.

yang
  • 31
  • 1
  • 10
  • I wonder if what library path the executable links against in the end (if it's what you see is in Xcode or not). Does it run in Xcode, but not when double clicking or you get this crash in Xcode directly ? what do you get if you run: `otool -L /Users/yangwang/Documents/cinder_projects/basic/xcode/build/Debug/basic.app/Contents/MacOS/basic | grep nite` ? – George Profenza May 29 '18 at 17:56
  • @GeorgeProfenza i added some updates. do they provide more info for you? – yang May 29 '18 at 21:26
  • what is the output of `otool -L` against your executable ? My hunch is is it has to do with how the .dylib is referenced (if it's an absolute path, using @rpath, @executable_path, etc.). Can you run the above long command command in Terminal and paste the output ? – George Profenza May 29 '18 at 22:52
  • @GeorgeProfenza the result is null. nothing fits the filter `nite` – yang May 30 '18 at 03:48
  • What does the output look like without the filter ? (`otool -L /Users/yangwang/Documents/cinder_projects/basic/xcode/build/Debug/basic.app/Contents/MacOS/basic`) – George Profenza May 30 '18 at 09:19
  • @GeorgeProfenza text too long , here is a screencap of it -> https://ibb.co/ky2vXd – yang May 30 '18 at 15:02

1 Answers1

0

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).

George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • i totally understood the intentions of the steps. it looks promising. but it didn't fix it. here is a picture showing the `otool` has be modified and `libNiTE2.dylib` is in place. : https://ibb.co/dSnzSd same old error msg when running in xcode. and double click .app shows nothing. – yang May 30 '18 at 19:58
  • Thank you for giving it a go. I thought that would sort it out. Can you let me know which version of cinder/xcode/OpenNI2 cinder block you're using ? (I'm busy these days, but at some point it would be good to figure out) – George Profenza May 30 '18 at 20:10
  • 1
    cinder version: 0.9.1, not using any openni2 cinder block. download the openni2's latest version straight from https://structure.io/openni – yang May 30 '18 at 20:13