bengfarrell / nuimotion

Node.js wrapper for OpenNI/NiTE offering skeletal joint tracking and gestures
http://www.sweatintotheweb.com/nuimotion-for-node-js/
MIT License
74 stars 19 forks source link

Building on OSX #12

Closed gordonturner closed 10 years ago

gordonturner commented 10 years ago

Hi Ben,

Was hoping you could help me out, I have installed the OSX OpenNI, NiTe and freenect pacakages.

(Also, I think I have the folder structure correct, please correct me if I have messed something up?)

OSX Mavericks Node v0.10.20 Xbox 360 Kinect

npm install node-gyp
mkdir -p ~/tmp/node_modules
cd ~/tmp/node_modules
wget https://github.com/bengfarrell/nuimotion/archive/master.zip
unzip master.zip
mv nuimotion-master nuimotion
cp -R ~/Developer/Work/OpenNI-MacOSX-x64-2.2/Redist/ ~/tmp/
cp -R ~/Developer/Work/NiTE-MacOSX-x64-2.2/Redist/ ~/tmp/
$ cd ~/tmp/node_modules/nuimotion
$ node-gyp rebuild
$ node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@0.12.1
gyp info using node@0.10.20 | darwin | x64
gyp info spawn python
gyp info spawn args [ '/usr/local/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/gturner/tmp/node_modules/nuimotion/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/gturner/.node-gyp/0.10.20/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/gturner/.node-gyp/0.10.20',
gyp info spawn args   '-Dmodule_root_dir=/Users/gturner/tmp/node_modules/nuimotion',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CXX(target) Release/obj.target/nuimotion/src/Main.o
  CXX(target) Release/obj.target/nuimotion/src/enums/EnumMapping.o
  CXX(target) Release/obj.target/nuimotion/src/gestures/GestureRecognizer.o
  CXX(target) Release/obj.target/nuimotion/src/gestures/Swipe.o
../src/gestures/Swipe.cpp:378:31: warning: comparison of integers of different signs: 'int' and 'clock_t' (aka 'unsigned long') [-Wsign-compare]
            if (_startTimeSwipeRight == clock() ) {
                ~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~
1 warning generated.
  CXX(target) Release/obj.target/nuimotion/src/gestures/Wave.o
  SOLINK_MODULE(target) Release/nuimotion.node
ld: library not found for -l../../
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Release/nuimotion.node] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Darwin 13.0.0
gyp ERR! command "node" "/usr/local/bin/node-gyp" "rebuild"
gyp ERR! cwd /Users/gturner/tmp/node_modules/nuimotion
gyp ERR! node -v v0.10.20
gyp ERR! node-gyp -v v0.12.1
gyp ERR! not ok 
vi ~/tmp/node_modules/nuimotion/binding.gyp
...
        # -Wl,-rpath will warn of failure on Windows, don't worry - it's a Linux thing, let it fail
        # CHANGED Commented out for OSX, libs already on build path?
        #"libraries": ["-l<(ONI_Root)OpenNI2", "-l<(ONI_Root)NiTE2", "-Wl,-rpath ./"]
...
cd ~/tmp/node_modules/nuimotion
node-gyp rebuild
vi ~/tmp/node_modules/nuimotion/index.js
...
module.exports = require('./build/Release/nuimotion.node');
...
cd ~/tmp
cp ~/tmp/node_modules/nuimotion/quickstart/basicquickstart.js ~/tmp/
node basicquickstart.js
Nui Motion Initialize 
Initialize Depth Camera
dyld: lazy symbol binding failed: Symbol not found: _niteInitialize
  Referenced from: /Users/gturner/tmp/node_modules/nuimotion/build/Release/nuimotion.node
  Expected in: dynamic lookup
dyld: Symbol not found: _niteInitialize
  Referenced from: /Users/gturner/tmp/node_modules/nuimotion/build/Release/nuimotion.node
  Expected in: dynamic lookup
Trace/BPT trap: 5

I guess my question is did my edit of binding.gyp cause the dyld error, and if so, do you have any suggestions for correcting binding.gyp?

Thanks! Gord.

bengfarrell commented 10 years ago

Hey Gordon - I had a previous issue with someone else who had the same problem. It turned out that my understanding of the linking was incorrect in the binding.gyp file. I thought I was successfully dynamically linking to the file on that line 31 you're looking at, but I was mistaken.

Instead, on my system, I already had OpenNI/NITE installed in a place where the sytem/env variables were already pointing to it, forgotten these were in place and incorrectly thought that I was successfully linking.

So I would suggest one more step in this. Leave the binding.gyp file so it compiles for you, and follow the instructions on the OpenNI website to install OpenNI and NITE - ensuring that these end up properly linked on your system.

I will tell you that I haven't tried this on OSX or with Freenect and an XBOX Kinect, though! I'm curious to see how it goes - because I know that OpenNI does not support the Kinect on platforms other than Windows - so I'm not sure what hoops you need to jump through with Freenect (if any).

Good luck!

gordonturner commented 10 years ago

Crud, I was hoping you had run it on OSX with Freenet and and XBOX Kinect :-)

Anyway, I am using brew to install things:

brew uninstall libusb
brew install libusb --universal
brew tap totakke/openni2
brew install openni2
brew install libfreenect
brew install openni2-freenectdriver
vi ~/.bash_profile
export OPENNI2_INCLUDE=/usr/local/include/ni2
export OPENNI2_REDIST=/usr/local/lib/ni2

I am not sure what env variable I need to add the library paths too, on Linux IIRC I would use ldconfig.

Any ideas?

gordonturner commented 10 years ago
vi ~/.bash_profile
export OPENNI2_INCLUDE=/usr/local/include/ni2
export OPENNI2_REDIST=/usr/local/lib/ni2
export DYLD_LIBRARY_PATH=$OPENNI2_INCLUDE:$OPENNI2_REDIST:/usr/local/lib
$ node basicquickstart.js
dyld: Symbol not found: __cg_png_create_info_struct
  Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
  Expected in: /usr/local/lib/libPng.dylib
 in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Trace/BPT trap: 5
bengfarrell commented 10 years ago

Unfortunately, no! In theory OpenNI/NiTE should run fine on OS (basically all cross platform between that Node/V8), but of course the XBOX Kinect isn't supported which is probably where you're still running into difficulty. The error message you're receiving doesn't look like anything I've encountered, which makes me thinks it's lower level like with Freenect vs OpenNI2. You might want to back up and run the OpenNI samples in their redistributable to ensure they work with your setup before banging on my project too much.

It sounds like from your second message that you have the paths in place for linking - but that error is preventing you from running things (though - you say you can't reproduce, so I'm not quite sure where you are!)

gordonturner commented 10 years ago

Hey Ben,

That's the frustrating part, I have OpenNI sample apps running, I even have OpenNI/NiTE add on for OpenFramework working on OSX.

Nuimotion is more useful because it has the swipe gestures and node (which should mean an easy way to access websockets).

Sorry if you feel I am banging on your project, I just feel like I am so close to pulling it together.

bengfarrell commented 10 years ago

No worries at all! No feeling like that - you're being quite nice, and I can understand the frustration on being so close. So, one other thing I can think of is the fact that when I wrote this, I did so from the 2.0 releases of OpenNI. I believe I had tried with the 2.1 release, but I definitely hadn't tried with 2.2 yet.

There are a fair amount of files I copied from the OpenNI/NiTE releases that I placed in src/common and src/include that perhaps are out of date with the latest release. These get referenced during the gyp build process, and it stands to reason that OpenNI includes some new functionality that are missing from these older include files. Perhaps replacing these files with the new, you'll fair better?

I do need to go back and run the project against 2.2, and especially test against your scenarios with the Kinect and OSX, but I just hadn't found the time yet. If you learn anything, please do share/contribute!

gordonturner commented 10 years ago

I am going to have to try another approach (I have a deadline), but I have put my notes in this gist:

https://gist.github.com/gordonturner/7861471

Included are references to other people with similar node-gyp + dyld isses, like this: http://stackoverflow.com/questions/19849325/node-opencv-mavericks-dyld-symbol-not-found https://github.com/peterbraden/node-opencv/issues/87

G.

bengfarrell commented 10 years ago

Thanks for the notes, sorry I couldn't get you up and running quickly.

I pulled out my work MacBook Air this afternoon because I finally had a couple hours to sit down. I found a couple of things...

First, the build process works perfectly as is - assuming the env vars are exported correctly on your system. I had copied over the libOpenNI2 and libNiTE2 dylib files over to /usr/local/lib as you had done. I then did export OpenNI2=/usr/local/lib and then likewise for NiTE2.

This creates the correct env variables for the binding.gyp file to pick up. Your step of removing that line from binding.gyp was no good. You need to keep the dynamic linked libraries in there or the dylib files won't be found at runtime.

Removing that step means that you correctly compile, but it's not good for running the thing. That line you removed from binding.gyp references these export names.

Unfortunately, I'm a little stuck - because I built it fine, but it says that my Node.js reference to the built file nuimotion.node is an unrecognized file type. This is a new one on me. I'll probably hit up the node mailing list for common causes.

Thanks for the kick in the ass to try this on OSX, and again sorry we couldn't figure it out for your deadline

alastaircoote commented 10 years ago

My issues with OS X here seem a little similar, but also different. I've got the libraries installed fine, so I don't have issues with compilation. Except that the instructions given don't work. If I run

node-gyp rebuild

in src/ it fails because it can't find binding.gyp. If I copy binding.gyp into src it also doesn't work. But if I back up one and run node-gyp rebuild in the nuimotion directory itself it builds fine, creating nuimotion.node in nuimotion/build.

But then index.js doesn't work, as it does this:

module.exports = require('./src/build/Release/nuimotion.node');

when the library is in ./build, not ./src/build. If I change that it appears to load correctly, but skeleton.js immediately fails. I think that as a result of all my moving files around, it's now not finding the OpenNI2 and NiTE2 directories correctly (they are in nuimotion/). Does that sound possible?

alastaircoote commented 10 years ago

I have (partially) solved my problem- it turns out that it's looking for drivers in /usr/local/lib/OpenNI2/drivers - which isn't what I wanted, but it does work for now.

bengfarrell commented 10 years ago

Happy to hear that. My primary platform had been Ubuntu and secondarily Windows. I was disappointed when I tried to build on OSX and was having errors when trying to load the build add-on. Glad you got it working.

And yes - unfortunately it seems like you really need to use that environmental path when building this as opposed to linking to OpenNI/NiTE from wherever you want. I had mistakenly thought I had this working before - but it had always just hit that folder that you mentioned.

kiya69 commented 10 years ago

Hi all, I am also working on a Mac OSX 10.9. Thanks for all the previous posts, I can get the nuimotion.node build without error. However, when I ran node basicquickstart, I am getting this kind of error: $ node basicquickstart.js Nui Motion Initialize

/Users/kiya/Kinect/nuimotion/quickstart/basicquickstart.js:13 nuimotion.Joints.LEFT_HAND, ^ TypeError: Cannot read property 'LEFT_HAND' of undefined at Object. (/Users/kiya/Kinect/nuimotion/quickstart/basicquickstart.js:13:21) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:902:3 I have tried to move my OpenNI2 and NiTE2 folders to /usr/local/lib/ too, but it's still the same. Can someone help me here? I am very new to node.js but it would be great to have some direction of where should I look for to fix this. Much appreciate!

bengfarrell commented 10 years ago

Hi Kiya, you may have missed the instructions at the top of the JS file. Since you're new to Node.js, I'll walk you through a little more as well. I'm seeing that you might not have your project set up quite right. NuiMotion is designed as a node plugin/module/addon. Typically when you use a node plugin, it will end up in a node_modules folder by default.

More often than not, you're installing plugins via npm (Node Package Manager). I've registered this plugin on NPM, so normally, you'd create a node project with something like a Main.js file containing the typical "hello world" starter. Within the same directory, you'd run "npm install nuimotion" from the command line (or use a package.json file to manage your dependencies).

This would create a node_modules folder, and install the nuimotion plugin inside. That "basicquickstart" script I created is meant to be run in your main project directory rather than the NuiMotion plugin folder. You could either copy the file there or copy and paste the code into your Main.js file.

The problem of it running where you have it, is that when we require('nuimotion'), it looks inside the node_modules folder for the nuimotion folder. It picks up the index.js file I have in the plugin as the main entrypoint - and all that nuimotion context gets assigned to the nuimotion variable.

Without the folder structure like that, I'm imagining that either most of the guts of the plugin aren't loaded - or if they are, my extra stuff from index.js is never put in that context. This extra stuff is adding on a Joints object to the scope of the plugin - and other simple object mapping.

Hope that makes sense! good luck

mrose17 commented 10 years ago

@bengfarrell - was there ever a consensus on what is needed for a mac install? i've tried with your steps and with @gordonturner 's steps. his got me a lot further, but it's still complaining about not being able to find -l…OpenNI despite the DYLD_LIBRARY_PATH trick.

my next step is to try on linux, but i'd like to get it going on a mac too... thanks!

gordonturner commented 10 years ago

@mrose17 I have completed a 'virgin' install for OSX and Ubuntu.

I will post the OSX instructions this evening.

mrose17 commented 10 years ago

Groovy! Mamy thanks!

/mtr via iPhone

On Feb 22, 2014, at 11:54, gordonturner notifications@github.com wrote:

@mrose17 I have completed a 'virgin' install for OSX and Ubuntu.

I will post the OSX instructions this evening.

— Reply to this email directly or view it on GitHub.

bengfarrell commented 10 years ago

Thanks guys, you rock for investigating. Its been a while since I've had a chance to pick up this project again, but i did just dive in this past week to get some raw depth stream stuff working from OpenNI. While there, I saw that I could much improve and simplify the build dependencies. I've got it working in Windows, and I'll be testing in Ubuntu and hopefully OSX tomorrow.

The basic change will be that there will no longer be manually moving files into your project. Just install OpenNI and NITE, and the build gyp will link during compile to an environmental variable pointing to your installation, and then it will copy the required DLL or so files into the build.

Like I said, assuming Ubuntu and OSX is as easy as Windows was, I should be able to get something new out tomorrow

gordonturner commented 10 years ago

As promised, here are the notes I created for a 'virgin' OSX Mavericks install.

http://blog.gordonturner.ca/b/AyE

I used an external USB 3 drive to boot and test from. Feed back is welcome, here or on the blog.

mrose17 commented 10 years ago

many thanks. my hope is to try it out in a few hours and let you know!

mrose17 commented 10 years ago

@gordonturner - i wasn't sure were to put comments, but here we go… two thus far:

i don't know where the

    /usr/local/lib/OpenNI2-Freenect/Driver/

came from, viz.,

    cp /usr/local/lib/OpenNI2-FreenectDriver/libFreenectDriver.dylib \
    ~/Developer/Work/OpenNI-MacOSX-x64-2.2/Redist/OpenNI2/Drivers/

the command that i had to run was

    cp /usr/local/Cellar/openni2-freenectdriver/1.2.1/libFreenectDriver.dylib \
    ~/Developer/Work/OpenNI-MacOSX-x64-2.2/Redist/OpenNI2/Drivers/

i think that DYLD_LIBRARY_PATH probably needs to be defined like this:

    export DYLD_LIBRARY_PATH=/usr/local/lib/OpenNI2/Drivers

the page you have gives this:

    export DYLD_LIBRARY_PATH=/usr/local/lib64/:/usr/local/lib64/OpenNI2-FreenectDriver/:/usr/local/lib:$DYLD_LIBRARY_PATH

and i have no idea where the

    /usr/local/lib64/*

came from. after making those two changes i was able to get

    % node-gyp rebuild

to run just fine!

with a little luck, early next week i can now try it out!

many thanks!

gordonturner commented 10 years ago

@mrose17 wrt to /usr/local/lib/OpenNI2-Freenect/Driver/ it was installed from source (Install freenect from github step), based on your changes, you already installed it from brew.

As a result of installing it with brew, the DYLD_LIBRARY_PATH values will be different too.

The one thing to keep in mind is that the version install via brew appears to be different from the GitHub version.

One reason I used the GitHub version is that it (for sure) included the OpenNI2-FreenectDriver.

G.

gordonturner commented 10 years ago

Just posted the Ubuntu install notes here: http://blog.gordonturner.ca/b/AzQ.

gordonturner commented 10 years ago

FYI @bengfarrell, I have the notes I posted in markdown format if you wanted to include them in your setup/install instructions.

bengfarrell commented 10 years ago

Absolutely - I've been hesitating a little, because I'm still trying to make the build process easier, and then wanted to validate it against your instructions.

But, I'm having a hell of a time getting NiTE in a state where it doesn't silently fail, so if I don't make good progress tonight, I'm just going to post your instructions.

thanks so much for all your effort! Either I will post it directly, or use them for testing as I create some new docs

gordonturner commented 10 years ago

@bengfarrell here are the 'raw' markdown notes: https://gist.github.com/gordonturner/9230241 https://gist.github.com/gordonturner/9230258

bengfarrell commented 10 years ago

Gordon, thanks again for these instructions. I've just revved to 0.2 to simplify building, so they might screw them up a little (hopefully not). I've moved your notes to the main readme, and will try to clean things up and review this weekend before publishing the new version to npm.

Freenect seems like the best way forward with the Apple purchase of Primesense and the lack of depth sensors, so I'm sure your notes will be of great help to someone.