Skip to content

Commit

Permalink
ffiimp.js: Fix compatibility with older node.js version
Browse files Browse the repository at this point in the history
They seem to expect main() to be included in the dynamic libraries. Odd.

For testing on a Mac, I now encounter issues discussed at:
https://github.com/node-ffi/node-ffi/pull/363/files
  • Loading branch information
Jason Kridner committed May 24, 2018
1 parent 9918a09 commit a059836
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/ffiimp.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,16 @@ var loadCModule = function (path, args, mraa) {
if (path.indexOf('.c') != -1)
path = path.replace('.c', '');
mraa = mraa || false; // link mraa
var outPath = path + '.so';
var inPath = path + '.c';
var shellCmd = 'gcc -shared -fpic ' + inPath + ' -o ' + outPath;
var shellCmd = 'gcc -shared -fpic ' + inPath + ' -o ' + path + '.so';
if (mraa) shellCmd += ' -lmraa';
if (debug) winston.debug('loadCModule: shellCmd = ' + shellCmd);

// Consider not running if .so newer than .c
shell.exec(shellCmd);

if (ffi.exists)
return ffi.Library(outPath, args);
return ffi.Library(path, args);
else {
winston.info("loadCModule: Could not load module FFI");
return "ffi not loaded";
Expand Down
6 changes: 6 additions & 0 deletions test/test-ffi.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ int dummy()
printf("Hello, World!");
return 0;
}
int main()
{
printf("Should never run.");
return 1;
}
`

module.exports.testFFI = function (test) {
Expand Down

0 comments on commit a059836

Please sign in to comment.