如何从nodejs应用程序访问.so库

我有一段C代码,它返回一个string输出。 相同的api以.so文件的forms打包。

我如何直接在我的nodejs代码中使用.so文件。 我需要添加一些东西在我的C代码或有相同的节点中的标准机制..?

谢谢

你不能。 你可以做的是编写一个使用这个库的C可执行文件并返回一个输出。 你可以使用exec函数在你的js文件中调用它。

exec('/<path_to_executable>/executable', function (error, stdout, stderr) { console.log('stdout: ' + stdout); console.log('stderr: ' + stderr); if (error !== null) { console.log('exec error: ' + error); } }); 
Interesting Posts