Use C++ dynamic library from Node.js with node-ffi
$ g++ -dynamiclib -o libhello.dylib hello.cpp
$ ls
libhello.dylib hello.cpp hello.js
$ node hello.js
hello world
0
extern "C" { | |
int hello(); | |
} | |
#include <stdio.h> | |
int hello() { | |
printf("hello world\n"); | |
return 0; | |
} |
var ffi = require('ffi'); | |
var hello = new ffi.Library('libhello', { | |
'hello': ['int', []] | |
}); | |
console.log(hello.hello()) |
Use C++ dynamic library from Node.js with node-ffi
$ g++ -dynamiclib -o libhello.dylib hello.cpp
$ ls
libhello.dylib hello.cpp hello.js
$ node hello.js
hello world
0