当使用node-gyp构建IP2Location插件时,Nodejs为本机c库构建和链接错误

时间:2013-12-04 02:12:00

标签: javascript macos node.js compilation

我正在尝试为Nodejs使用IP2Location插件。使用 npm install ip2location 进行正常安装无济于事。像这样抛出错误

sh-3.2# npm install ip2location -g --verbose
npm info it worked if it ends with ok
npm verb cli [ 'node',
npm verb cli   '/usr/local/bin/npm',
npm verb cli   'install',
npm verb cli   'ip2location',
npm verb cli   '-g',
npm verb cli   '--verbose' ]
npm info using npm@1.3.14
npm info using node@v0.10.22
npm verb cache add [ 'ip2location', null ]
npm verb cache add name=undefined spec="ip2location" args=["ip2location",null]
npm verb parsed url { protocol: null,
npm verb parsed url   slashes: null,
npm verb parsed url   auth: null,
npm verb parsed url   host: null,
npm verb parsed url   port: null,
npm verb parsed url   hostname: null,
npm verb parsed url   hash: null,
npm verb parsed url   search: null,
npm verb parsed url   query: null,
npm verb parsed url   pathname: 'ip2location',
npm verb parsed url   path: 'ip2location',
npm verb parsed url   href: 'ip2location' }
npm verb lock ip2location /var/root/.npm/9f287e36-ip2location.lock
npm verb addNamed [ 'ip2location', '' ]
npm verb addNamed [ null, '*' ]
npm verb lock ip2location@ /var/root/.npm/10ff5e0e-ip2location.lock
npm verb url raw ip2location
npm verb url resolving [ 'https://registry.npmjs.org/', './ip2location' ]
npm verb url resolved https://registry.npmjs.org/ip2location
npm info trying registry request attempt 1 at 08:59:10
npm verb etag "B0D5VZ1AHUA0A2VRYEJBYO4E"
npm http GET https://registry.npmjs.org/ip2location
npm http 304 https://registry.npmjs.org/ip2location
npm verb etag ip2location from cache
npm verb addNamed [ 'ip2location', '0.1.2' ]
npm verb addNamed [ '0.1.2', '0.1.2' ]
npm verb lock ip2location@0.1.2 /var/root/.npm/fe0d76fc-ip2location-0-1-2.lock
npm info install ip2location@0.1.2 into /usr/local/lib
npm info installOne ip2location@0.1.2
npm info /usr/local/lib/node_modules/ip2location unbuild
npm verb tar unpack /var/root/.npm/ip2location/0.1.2/package.tgz
npm verb lock tar:///usr/local/lib/node_modules/ip2location /var/root/.npm/30456df6-cal-lib-node-modules-ip2location.lock
npm verb lock tar:///var/root/.npm/ip2location/0.1.2/package.tgz /var/root/.npm/0a77758d-pm-ip2location-0-1-2-package-tgz.lock
npm info preinstall ip2location@0.1.2
npm verb readDependencies using package.json deps
npm verb readDependencies using package.json deps
npm verb about to build /usr/local/lib/node_modules/ip2location
npm info build /usr/local/lib/node_modules/ip2location
npm verb linkStuff [ true,
npm verb linkStuff   '/usr/local/lib/node_modules',
npm verb linkStuff   true,
npm verb linkStuff   '/usr/local/lib/node_modules' ]
npm info linkStuff ip2location@0.1.2
npm verb linkBins ip2location@0.1.2
npm verb linkMans ip2location@0.1.2
npm verb rebuildBundles ip2location@0.1.2
npm info install ip2location@0.1.2

ip2location@0.1.2 install /usr/local/lib/node_modules/ip2location
node-gyp configure build

gyp info it worked if it ends with ok
gyp verb cli [ 'node',
gyp verb cli   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'configure',
gyp verb cli   'build' ]
gyp info using node-gyp@0.11.0
gyp info using node@0.10.22 | darwin | x64
gyp verb command configure []
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python /usr/bin/python
gyp verb check python version `python -c "import platform; print(platform.python_version());"` returned: "2.7.5\n"
gyp verb get node dir no --target version specified, falling back to host node version: v0.10.22
gyp verb command install [ 'v0.10.22' ]
gyp verb install input version string "v0.10.22"
gyp verb install installing version: 0.10.22
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 0.10.22
gyp verb build dir attempting to create "build" dir: /usr/local/lib/node_modules/ip2location/build
gyp verb build dir "build" dir needed to be created? /usr/local/lib/node_modules/ip2location/build
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: /usr/local/lib/node_modules/ip2location/build/config.gypi
gyp verb config.gypi checking for gypi file: /usr/local/lib/node_modules/ip2location/config.gypi
gyp verb common.gypi checking for gypi file: /usr/local/lib/node_modules/ip2location/common.gypi
gyp verb gyp gyp format was not specified; forcing "make"
gyp info spawn python
gyp info spawn args [ '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp',
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   '/usr/local/lib/node_modules/ip2location/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/var/root/.node-gyp/0.10.22/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/var/root/.node-gyp/0.10.22',
gyp info spawn args   '-Dmodule_root_dir=/usr/local/lib/node_modules/ip2location',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp verb command build []
gyp verb build type Release
gyp verb architecture x64
gyp verb node dev dir /var/root/.node-gyp/0.10.22
gyp verb `which` succeeded for `make` /usr/bin/make
gyp info spawn make
gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
  c++ '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' -I/var/root/.node-gyp/0.10.22/src -I/var/root/.node-gyp/0.10.22/deps/uv/include -I/var/root/.node-gyp/0.10.22/deps/v8/include  -Os -gdwarf-2 -mmacosx-version-min=10.5 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/ip2locationnode/src/ip2locationnode.o.d.raw  -c -o Release/obj.target/ip2locationnode/src/ip2locationnode.o ../src/ip2locationnode.cc
../src/ip2locationnode.cc:3:10: fatal error: 'IP2Location.h' file not found
#include <IP2Location.h>
         ^
1 error generated.
make: *** [Release/obj.target/ip2locationnode/src/ip2locationnode.o] 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/npm/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/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /usr/local/lib/node_modules/ip2location
gyp ERR! node -v v0.10.22
gyp ERR! node-gyp -v v0.11.0
gyp ERR! not ok 
npm verb unsafe-perm in lifecycle false
npm info ip2location@0.1.2 Failed to exec install script
npm info /usr/local/lib/node_modules/ip2location unbuild
npm info preuninstall ip2location@0.1.2
npm info uninstall ip2location@0.1.2
npm verb true,/usr/local/lib/node_modules,/usr/local/lib/node_modules unbuild ip2location@0.1.2
npm info postuninstall ip2location@0.1.2
npm ERR! ip2location@0.1.2 install: `node-gyp configure build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the ip2location@0.1.2 install script.
npm ERR! This is most likely a problem with the ip2location package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp configure build
npm ERR! You can get their info via:
npm ERR!     npm owner ls ip2location
npm ERR! There is likely additional logging output above.

npm ERR! System Darwin 13.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "ip2location" "-g" "--verbose"
npm ERR! cwd /
npm ERR! node -v v0.10.22
npm ERR! npm -v 1.3.14
npm ERR! code ELIFECYCLE
npm verb exit [ 1, true ]
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /npm-debug.log
npm ERR! not ok code 0

基于此,我假设它需要安装IP2Location库。我从这里得到了图书馆 http://www.ip2location.com/developers/c并使用提供的手册编译该库。 然后我下载了IP2Location源代码,将binding.gyp编辑为

{
  'targets': [
    {
      'target_name': 'ip2locationnode',
      'sources': [ 'src/ip2locationnode.cc' ],
      'include_dirs': [ 'lib','lib/iMath' ],
      'link_settings': {
          'libraries': [
              '-I/Users/mobafone/Downloads/node-ip2location-master/lib',
              '-I/Users/mobafone/Downloads/node-ip2location-master/lib/iMath'
          ]
      }
    }
  ]
}

我尝试使用此结果运行node-gyp configure build

gyp info it worked if it ends with ok
gyp verb cli [ 'node',
gyp verb cli   '/usr/local/bin/node-gyp',
gyp verb cli   'configure',
gyp verb cli   'build',
gyp verb cli   '--verbose' ]
gyp info using node-gyp@0.12.1
gyp info using node@0.10.22 | darwin | x64
gyp verb command configure []
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python /usr/bin/python
gyp verb check python version `python -c "import platform; print(platform.python_version());"` returned: "2.7.5\n"
gyp verb get node dir no --target version specified, falling back to host node version: v0.10.22
gyp verb command install [ 'v0.10.22' ]
gyp verb install input version string "v0.10.22"
gyp verb install installing version: 0.10.22
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 0.10.22
gyp verb build dir attempting to create "build" dir: /Users/mobafone/Downloads/node-ip2location-master/build
gyp verb build dir "build" dir needed to be created? /Users/mobafone/Downloads/node-ip2location-master/build
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: /Users/mobafone/Downloads/node-ip2location-master/build/config.gypi
gyp verb config.gypi checking for gypi file: /Users/mobafone/Downloads/node-ip2location-master/config.gypi
gyp verb common.gypi checking for gypi file: /Users/mobafone/Downloads/node-ip2location-master/common.gypi
gyp verb gyp gyp format was not specified; forcing "make"
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/mobafone/Downloads/node-ip2location-master/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/mobafone/.node-gyp/0.10.22/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/mobafone/.node-gyp/0.10.22',
gyp info spawn args   '-Dmodule_root_dir=/Users/mobafone/Downloads/node-ip2location-master',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp verb command build []
gyp verb build type Release
gyp verb architecture x64
gyp verb node dev dir /Users/mobafone/.node-gyp/0.10.22
gyp verb `which` succeeded for `make` /usr/bin/make
gyp info spawn make
gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
  c++ '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' -I/Users/mobafone/.node-gyp/0.10.22/src -I/Users/mobafone/.node-gyp/0.10.22/deps/uv/include -I/Users/mobafone/.node-gyp/0.10.22/deps/v8/include -I../lib -I../lib/iMath  -Os -gdwarf-2 -mmacosx-version-min=10.5 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/ip2locationnode/src/ip2locationnode.o.d.raw  -c -o Release/obj.target/ip2locationnode/src/ip2locationnode.o ../src/ip2locationnode.cc
  ./gyp-mac-tool flock ./Release/linker.lock c++ -bundle -Wl,-search_paths_first -mmacosx-version-min=10.5 -arch x86_64 -L./Release  -o Release/ip2locationnode.node Release/obj.target/ip2locationnode/src/ip2locationnode.o -undefined dynamic_lookup -I/Users/mobafone/Downloads/node-ip2location-master/lib -I/Users/mobafone/Downloads/node-ip2location-master/lib/iMath
  SOLINK_MODULE(target) Release/ip2locationnode.node: Finished
gyp info ok 

但是当我尝试使用 node example.js 运行example.js时,我得到了这个结果

dyld: lazy symbol binding failed: Symbol not found: _IP2Location_open
  Referenced from: /Users/mobafone/Downloads/node-ip2location-master/build/Release/ip2locationnode.node
  Expected in: dynamic lookup

dyld: Symbol not found: _IP2Location_open
  Referenced from: /Users/mobafone/Downloads/node-ip2location-master/build/Release/ip2locationnode.node
  Expected in: dynamic lookup

Trace/BPT trap: 5

这是otool -L build / Release / ip2locationnode.node

/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 60.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 2577.0.0)

出了什么问题?

更新

我用make和sudo make install和put重新编译IP2Location     DYLD_LIBRARY_PATH =的/ usr /本地/ LIB /

来自node-gyp configure build

的新结果
gyp info it worked if it ends with ok
gyp verb cli [ 'node',
gyp verb cli   '/usr/local/bin/node-gyp',
gyp verb cli   'configure',
gyp verb cli   'build',
gyp verb cli   '--verbose' ]
gyp info using node-gyp@0.12.1
gyp info using node@0.10.22 | darwin | x64
gyp verb command configure []
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python /usr/bin/python
gyp verb check python version `python -c "import platform; print(platform.python_version());"` returned: "2.7.5\n"
gyp verb get node dir no --target version specified, falling back to host node version: v0.10.22
gyp verb command install [ 'v0.10.22' ]
gyp verb install input version string "v0.10.22"
gyp verb install installing version: 0.10.22
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 0.10.22
gyp verb build dir attempting to create "build" dir: /Users/mobafone/Downloads/node-ip2location-master/build
gyp verb build dir "build" dir needed to be created? null
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: /Users/mobafone/Downloads/node-ip2location-master/build/config.gypi
gyp verb config.gypi checking for gypi file: /Users/mobafone/Downloads/node-ip2location-master/config.gypi
gyp verb common.gypi checking for gypi file: /Users/mobafone/Downloads/node-ip2location-master/common.gypi
gyp verb gyp gyp format was not specified; forcing "make"
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/mobafone/Downloads/node-ip2location-master/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/mobafone/.node-gyp/0.10.22/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/mobafone/.node-gyp/0.10.22',
gyp info spawn args   '-Dmodule_root_dir=/Users/mobafone/Downloads/node-ip2location-master',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp verb command build []
gyp verb build type Release
gyp verb architecture x64
gyp verb node dev dir /Users/mobafone/.node-gyp/0.10.22
gyp verb `which` succeeded for `make` /usr/bin/make
gyp info spawn make
gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
  ./gyp-mac-tool flock ./Release/linker.lock c++ -bundle -Wl,-search_paths_first -mmacosx-version-min=10.5 -arch x86_64 -L./Release  -o Release/ip2locationnode.node Release/obj.target/ip2locationnode/src/ip2locationnode.o -undefined dynamic_lookup -lIP2Location
ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file '/usr/local/lib/libIP2Location.so' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Release/ip2locationnode.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" "configure" "build" "--verbose"
gyp ERR! cwd /Users/mobafone/Downloads/node-ip2location-master
gyp ERR! node -v v0.10.22
gyp ERR! node-gyp -v v0.12.1
gyp ERR! not ok

我没有使用IP2Location nodejs包,因为我正在处理遗留代码。与安装和配置插件相比,重写它需要一些努力。我在基于linux的软件包中编译它没有任何问题,但由于开发人员机器是Mac OSX Mavericks,它严重限制了我可以用它做什么。

1 个答案:

答案 0 :(得分:1)

你试过这个吗? IP2Location实际上是https://npmjs.org/package/ip2location-nodejs