node-ffi-napi / node-ffi-napi

A foreign function interface (FFI) for Node.js, N-API style
MIT License
1.01k stars 147 forks source link

Error: Dynamic Linking Error: Win32 error 126 When Calling a Go .so file with node-ffi-napi #142

Open Humphryyy opened 3 years ago

Humphryyy commented 3 years ago
var ref = require("ref");
var ffi = require("ffi");
var Struct = require("ref-struct")
var ArrayType = require("ref-array")
var LongArray = ArrayType(ref.types.longlong);
var GoSlice = Struct({
  data: LongArray,
  len:  "longlong",
  cap: "longlong"
});
var GoString = Struct({
  p: "string",
  n: "longlong"
});
var awesome = ffi.Library("./awesome.so", {
  Add: ["longlong", ["longlong", "longlong"]],
  Cosine: ["double", ["double"]],
  Sort: ["void", [GoSlice]],
  Log: ["longlong", [GoString]]
});
console.log("awesome.Add(12, 99) = ", awesome.Add(12, 99));
console.log("awesome.Cosine(1) = ", awesome.Cosine(1));
nums = LongArray([12,54,0,423,9]);
var slice = new GoSlice();
slice["data"] = nums;
slice["len"] = 5;
slice["cap"] = 5;
awesome.Sort(slice);
str = new GoString();
str["p"] = "Hello Node!";
str["n"] = 11;
awesome.Log(str);

I've tried with a few other examples and I get the same error on them all.

I am trying to call a Go .so file and I am getting this error.

bianyuanop commented 3 years ago

I have this error too, but no idea how it would happend

const ffi = require('ffi-napi');
const path = require('path');
const libPath = path.join(process.cwd(), 'engine/unitsync.dll');
console.log(libPath);

var libunitsync = ffi.Library(libPath, {
    'Init': [
        'int', 
        ['bool', 'int']
    ],
    'GetMapCount': [
        'int',
        []
    ]
});

isOpen = libunitsync.Init(0, 0);
console.log(isOpen);
mapCount = libunitsync.GetMapCount();
console.log(mapCount);

and the unitsync.dll is in follow: http://files.ultirts.net/fileXchanger/unitsync.dll

fs15682014427 commented 11 months ago

Has the problem been solved?