2012-02-24 60 views
0

我跟着Writing Node.js Native Extension成功創建了helloworld.node文件。我可以成功撥打helloworld.nodeNode.js C++擴展部署

而且,我有打電話helloworld.node一個test.js。的test.js內容是

var mhw = require('./helloworld/build/Release/helloworld'); 
var hw = new mhw.HelloWorld(); 
console.log(hw.hello()); 

但我得到Unable to load shared library錯誤我感動helloworld.nodetest.js到另一臺計算機後。

hkalex(at)shellmix ~/nodetest> node test.js 

node.js:201 
     throw e; // process.nextTick error, or 'error' event on first tick 
      ^
Error: Unable to load shared library /homex/hkalex/nodetest/helloworld/build/Release/helloworld.node 
    at Object..node (module.js:463:11) 
    at Module.load (module.js:351:31) 
    at Function._load (module.js:310:12) 
    at Module.require (module.js:357:17) 
    at require (module.js:368:17) 
    at Object.<anonymous> (/homex/hkalex/nodetest/test.js:1:73) 
    at Module._compile (module.js:432:26) 
    at Object..js (module.js:450:10) 
    at Module.load (module.js:351:31) 
    at Function._load (module.js:310:12) 
hkalex(at)shellmix ~/nodetest> 

我在開發計算機中使用root。我正在使用shellmix進行測試。

有什麼想法嗎?謝謝!

更新

如果我把源文件中shellmix並從源代碼編譯,一切都很好。

回答

1

我想在另一臺機器上你沒有相同的CPU架構或操作系統,並且你有機器特定的代碼。通常對於節點本地模塊,它們分發源代碼,並在目標機器上的npm install上自動編譯,以確保它在其機器上正常工作。如果使用gcc,則可以指定cpu體系結構(添加-m32或-m64)。

如果您想編譯爲其他操作系統,最簡單的方法是在OS上編譯,您也可以在虛擬機上使用virtualboxVMware player進行編譯。

您也可以編譯爲其他操作系統比你在使用交叉編譯器之一,但不推薦,因爲,這將需要一些時間來建立並學會使用。說明書是herehere