chrisdew / protobuf

Protocol Buffers for Node.JS
http://code.google.com/p/protobuf-for-node/
Apache License 2.0
234 stars 71 forks source link

Node cannot find the protobuf module #4

Closed bhelx closed 12 years ago

bhelx commented 12 years ago

Compile seems to work out except for a few warnings but node can't find the module when requiring.

rsa:pbtest bhelx$ npm install protobuf
npm http GET https://registry.npmjs.org/protobuf
npm http 304 https://registry.npmjs.org/protobuf

> protobuf@0.3.0 install /Users/bhelx/node_modules/protobuf
> PROTOBUF=/usr/local/lib node-waf configure clean build

Checking for program g++ or c++          : /usr/bin/g++ 
Checking for program cpp                 : /usr/bin/cpp 
Checking for program ar                  : /usr/bin/ar 
Checking for program ranlib              : /usr/bin/ranlib 
Checking for g++                         : ok  
Checking for node path                   : ok /usr/local/lib/node_modules/ 
Checking for node prefix                 : ok /usr/local 
'configure' finished successfully (0.044s)
'clean' finished successfully (0.005s)
Waf: Entering directory `/Users/bhelx/node_modules/protobuf/build'
[1/7] cxx: protobuf_for_node.cc -> build/Release/protobuf_for_node_1.o
[2/7] cxx: addon.cc -> build/Release/addon_2.o
[3/7] cxx: example/protoservice.pb.cc -> build/Release/example/protoservice.pb_3.o
[4/7] cxx: example/protoservice.cc -> build/Release/example/protoservice_3.o
[5/7] cxx_link: build/Release/protobuf_for_node_1.o -> build/Release/libprotobuf_for_node_lib.dylib
ld: warning: directory '/usr/local/lib/lib' following -L not found
[6/7] cxx_link: build/Release/example/protoservice.pb_3.o build/Release/example/protoservice_3.o -> build/Release/protoservice.node
[7/7] cxx_link: build/Release/addon_2.o -> build/Release/protobuf_for_node.node
ld: warning: directory '/usr/local/lib/lib' following -L not found
ld: warning: directory '/usr/local/lib/lib' following -L not found
Waf: Leaving directory `/Users/bhelx/node_modules/protobuf/build'
'build' finished successfully (4.046s)
protobuf@0.3.0 ../../../node_modules/protobuf
rsa:pbtest bhelx$ ls ../../../node_modules/protobuf/build/Release/
total 1736
drwxr-xr-x  8 bhelx  staff     272 Apr 22 14:58 .
drwxr-xr-x  6 bhelx  staff     204 Apr 22 14:58 ..
-rw-r--r--  1 bhelx  staff   45184 Apr 22 14:58 addon_2.o
drwxr-xr-x  4 bhelx  staff     136 Apr 22 14:58 example
-rwxr-xr-x  1 bhelx  staff   79848 Apr 22 14:58 libprotobuf_for_node_lib.dylib
-rwxr-xr-x  1 bhelx  staff    9064 Apr 22 14:58 protobuf_for_node.node
-rw-r--r--  1 bhelx  staff  664688 Apr 22 14:58 protobuf_for_node_1.o
-rwxr-xr-x  1 bhelx  staff   77312 Apr 22 14:58 protoservice.node

rsa:pbtest bhelx$ node
> require('protobuf')
Error: Cannot find module 'protobuf'
    at Function._resolveFilename (module.js:332:11)
    at Function._load (module.js:279:25)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at repl:1:2
    at REPLServer.eval (repl.js:80:21)
    at Interface.<anonymous> (repl.js:182:12)
    at Interface.emit (events.js:67:17)
    at Interface._onLine (readline.js:162:10)
    at Interface._line (readline.js:426:8)

Do you think it has something to do with those warnings?

bhelx commented 12 years ago

Still does the same thing after installing globally.

BTW, I am seeing this on CentOS and OS X, node version 0.6.15, npm version 1.1.16

englercj commented 12 years ago

This repo is not for 0.6.x I'm suprised you got it to compile, have you tried my fork at englercj/protobuf?

bhelx commented 12 years ago

Ah, I never noticed that this was targeted at 0.4. It seems to be doing the same thing with your fork though.

bhelx commented 12 years ago

NM, new error. A good sign:

> require('protobuf')
Error: Unable to load shared library /Users/bhelx/code/node/pbtest/node_modules/protobuf/build/Release/protobuf_for_node.node
    at Object..node (module.js:472:11)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at repl:1:2
    at REPLServer.eval (repl.js:80:21)
    at Interface.<anonymous> (repl.js:182:12)
    at Interface.emit (events.js:67:17)
    at Interface._onLine (readline.js:162:10)

I am on OS X at the moment and I dont have a /etc/ld.so.conf.d

englercj commented 12 years ago

I'm honestly not sure how OS X handles library paths, but you need to add the path to the compiled binary to that path.

chrisdew commented 12 years ago

There is a new version of protobuf on npm now - http://search.npmjs.org/#/protobuf . I've tested that it works with Node 0.6.9 on Ubuntu. Could you have a look with OSX please?

bhelx commented 12 years ago

Well, it's installing with no intervention right now, so that is good. But still getting that error. I think @englercj is correct about the library path issue but altering that on OS X causes issues, especially if you use homebrew. I am going to look into a workaround.

englercj commented 12 years ago

The Unable to load shared library error is definitely caused by either the compiled output of this package not being on your library path, or the libs built from Google's protobuf engine not being on your library path.

nabeelio commented 12 years ago

I'm getting the "unable to load shared library" on Ubuntu 10.04 Built protocol buffers direct from google

nabeelio commented 12 years ago

Adding the path to /Release to ldconfig manually made it go away and it seems to have loaded the library

sudo ldconfigpwd``

nabeelio commented 12 years ago

Ok, sorry for the repeated comments. I still have to add the path into ld.so.conf.d, which is a bit annoying but I'm not sure how to get around that.

booo commented 12 years ago

Does it really make sense to have a shared libprotobuf_for_node_lib? I don't want to issue a sudo ldconfigpwd`` every time I install this package. What's the use case for the shared lib?

chrisdew commented 12 years ago

@boo Sorry, I have no idea - I didn't write protobuf_for_node, I only packaged it. You're very welcome to fork and change the package so that the functionality of libprotobuf_for_node_lib is integrated into the .node file and send me a pull request.

zhaoke commented 12 years ago

echo "/usr/local/lib" | tee /etc/ld.so.conf.d/protobuf.conf && ldconfig

this the example result: Message after roundtrip: { "title": "Title" } Number of entries: 2 Proto: 22.96 us / object JSON: 2.58 us / object

much slower than JSON in Node

englercj commented 12 years ago

Now compare the size of the messages when encoded.

bhelx commented 12 years ago

Verified working with version 0.3.2 on OS X and Cent OS

cmingxu commented 12 years ago

Build failed: -> task failed (err #1): {task: cxx protobuf_for_node.cc -> protobuf_for_node_1.o} npm ERR! protobuf@0.3.1 install: PROTOBUF=/usr/local/lib node-waf configure clean build npm ERR! sh "-c" "PROTOBUF=/usr/local/lib node-waf configure clean build" failed with 1 npm ERR! npm ERR! Failed at the protobuf@0.3.1 install script. npm ERR! This is most likely a problem with the protobuf package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! PROTOBUF=/usr/local/lib node-waf configure clean build npm ERR! You can get their info via: npm ERR! npm owner ls protobuf npm ERR! There is likely additional logging output above.

npm ERR! System Darwin 12.1.0 npm ERR! command "/usr/local/Cellar/node/0.8.8/bin/node" "/usr/local/bin/npm" "install" "protobuf" npm ERR! cwd /Users/xcm/Code/work/game_studio/nodejs npm ERR! node -v v0.8.8 npm ERR! npm -v 1.1.59 npm ERR! code ELIFECYCLE npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /Users/xcm/Code/work/game_studio/nodejs/npm-debug.log

every time i try install protobuf on my macos i got this annoying error.

Not sure how to manage this, is there anybody having the same issue?