Skip to content

Instantly share code, notes, and snippets.

@ryosuzuki
Last active February 29, 2016 07:52
Show Gist options
  • Save ryosuzuki/d2eac95e64e2b0dd4156 to your computer and use it in GitHub Desktop.
Save ryosuzuki/d2eac95e64e2b0dd4156 to your computer and use it in GitHub Desktop.
Hello world with node-ffi
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())

Hello world with node-ffi

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment