简体   繁体   中英

Error when building node.js addon with node-gyp

I'm building a extremely simple node.js addon that just prints out the string "Hello". When I go to build it using "node-gyp build", I get an error:

gyp info it worked if it ends with ok
gyp info using node-gyp@1.0.2
gyp info using node@0.10.35 | darwin | x64
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CXX(target) Release/obj.target/hello/hello.o
  SOLINK_MODULE(target) Release/hello.node
clang: error: no such file or directory: '“-L/opt/local/lib”'  
make: *** [Release/hello.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.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:820:12)
gyp ERR! System Darwin 13.4.0
gyp ERR! command "node" "/usr/local/bin/node-gyp" "build"
gyp ERR! cwd /Users/Kevin/Development/node/sampleaddon
gyp ERR! node -v v0.10.35
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok 

First, I go and check if /opt/local/lib exists. It does, and it's full of files. I'm thinking that it is perhaps a permissions issue, so I run "sudo node-gyp build". That works great, and the addon builds without errors.

So it looks like it's permissions-related. So I look at the permissions:

Chipmunk:sampleaddon Kevin$ ls -l /opt/local
total 8
drwxr-xr-x    3 root  wheel    102 Feb  2  2014 Library
drwxr-xr-x  344 root  admin  11696 Mar 13  2014 bin
drwxr-xr-x    7 root  admin    238 Feb  2  2014 etc
drwxr-xr-x   70 root  admin   2380 Mar 13  2014 include
drwxr-xr-x  240 root  admin   8160 Mar 13  2014 lib
drwxr-xr-x    7 root  admin    238 Feb  2  2014 libexec
lrwxr-xr-x    1 root  admin      9 Feb  2  2014 man -> share/man
drwxr-xr-x    9 root  admin    306 Feb  2  2014 sbin
drwxr-xr-x   26 root  admin    884 Feb  2  2014 share
drwxr-xr-x    3 root  admin    102 Oct 25  2013 var

Everyone has read access to /opt/local/lib, so I'm not understanding what the issue is here. I'd like to build node addons without having to build them as root.

I npm installed node-gyp with the -g option, but that's the normal way to install it.

Does anyone have an idea what the issue could be?

Edit: Here's the binding.gyp file.

{
    "targets" : [
        {
            "target_name" : "hello",
            "sources" : [ "hello.cpp" ]           
        }
    ]
}

Here's what it looks like when I run "sudo node-gyp build":

Chipmunk:sampleaddon Kevin$ sudo node-gyp build
gyp info it worked if it ends with ok
gyp info using node-gyp@1.0.2
gyp info using node@0.10.35 | darwin | x64
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CXX(target) Release/obj.target/hello/hello.o
  SOLINK_MODULE(target) Release/hello.node
  SOLINK_MODULE(target) Release/hello.node: Finished
gyp info ok 

I don't know if it makes a difference, but I'm using OS X 10.9.5.

I found out what the issue is. The “-L/opt/local/lib” that node-gyp is having issues with is coming from the LDFLAGS environment variable. This environment variable was added by macports. For some reason, node-gyp is unable to cope with the quotations. I edited the .bash_profile file in my home directory and removed the quotations from around -L/opt/local/lib in LDFLAGS.

That worked, and I was able to compile the node.js addon. I have no idea why the quotations cause this issue. I have no idea how it would be possible to specify a link directory with a space in it if quotations are not allowed in the link path. If anyone does know how to have a node-gyp link path with a space in the directory name, please let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM