如何告诉本机node.js扩展在哪里找到(正确的)libstdc ++? [英] How do I tell a native node.js extension where to find (the right) libstdc++?

查看:274
本文介绍了如何告诉本机node.js扩展在哪里找到(正确的)libstdc ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在安装scrypt( https://www.npmjs.com/package/scrypt ).安装过程涉及一个node-gyp构建步骤,该步骤将构建本机node.js扩展.然后,当我启动我的应用程序时,它失败并显示以下错误:

I’m installing scrypt (https://www.npmjs.com/package/scrypt) from npm. The installation involves a node-gyp build step that builds a native node.js extension. When I then start my app, it fails with the following error:

node index.js 
module.js:568
  return process.dlopen(module, path._makeLong(filename));
                 ^

Error: /package/host/localhost/gcc-4/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /home/xxxx/xxxx/node_modules/scrypt/build/Release/scrypt.node)
    at Error (native)
    at Object.Module._extensions..node (module.js:568:18)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Module.require (module.js:466:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/xxxx/xxxx/node_modules/scrypt/index.js:3:20)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Module.require (module.js:466:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/xxxx/xxxx/node_modules/unfun-cms/lib/utils/password.js:3:16)

这并不奇怪,因为

[xxxx@xxxx nodeapp]$ strings /package/host/localhost/gcc-4/lib64/libstdc++.so.6 | grep "GLIBCXX_3\.4\.21"
[xxxx@xxxx nodeapp]$

同时

[xxxx@xxxx nodeapp]$ strings /package/host/localhost/gcc-5/lib64/libstdc++.so.6 | grep "GLIBCXX_3\.4\.21"
GLIBCXX_3.4.21
[xxxx@xxxx nodeapp]$

我有

export PATH=/package/host/localhost/gcc-5/bin:$PATH
export LD_LIBRARY_PATH=/package/host/localhost/gcc-5/lib64:$LD_LIBRARY_PATH

我的.bashrc中的

,并且gcc --version正确显示了5.2.0,因此我认为这些设置还可以.

in my .bashrc, and gcc --version shows 5.2.0 correctly, so I assume these settings are alright.

所以问题是,如何告诉scrypt正确的libstdc++.so.6路径,即/package/host/localhost/gcc-5/lib64/libstdc++.so.6处的路径? (为什么它会弄错呢?)

So the question is, how do I tell scrypt the path to the correct libstdc++.so.6, namely the one at /package/host/localhost/gcc-5/lib64/libstdc++.so.6? (And why does it even get it wrong?)

这是一台CentOS计算机.我正在使用node.js版本6.1.0,npm版本3.8.6,并且正在尝试安装scrypt版本6.0.3,这是在撰写本文时的最新版本.

This is a CentOS machine. I’m using node.js version 6.1.0, npm version 3.8.6, and I’m trying to install scrypt version 6.0.3, which is the latest version at the time of this writing.

我尝试通过编辑node_modules/scrypt/binding.gyp并添加

'libraries': ['/package/host/localhost/gcc-5/lib64/libstdc++.so.6'],

到四个指定目标中的每个目标,然后运行node-gyp rebuild.

to each of the four specified targets, and then running node-gyp rebuild.

我还尝试将其更改为

'libraries': ['-L/package/host/localhost/gcc-5/lib64', '-lstdc++'],

,从语法上看也是有效的,但仍然尝试在运行时从错误的路径加载库.

, which appears to be syntactically valid, too—but still, it tries to load the library from the wrong path at runtime.

推荐答案

我也遇到了类似的麻烦,并通过技巧通过动态加载libstdc ++.so.6通过LD_PRELOAD来解决它:

I stubled with a similar trouble and had resolve it with a trick uses dynamic load of libstdc++.so.6 through LD_PRELOAD:

LD_PRELOAD='/path/to/lib/libstdc++.so.6' /usr/bin/nodejs app.js

这篇关于如何告诉本机node.js扩展在哪里找到(正确的)libstdc ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆