I have a C library <code>clib.c</code> with this function. <code> int hi(char* 
hello) { return 900; }</code> compiled as: <code>gcc clib.c -o clib.so --shared 
-fPIC</code> I'm consuming this in a Nim libray called 'nlib.nim`:

<code> proc hi*(hello: cstring): cint {.cdecl, importc: "hi", dynlib: 
"./clib.so".} proc hi2*(hello: cstring): cint {.cdecl, exportc.} = return 
hi(hello)</code> complied as:

<code>nim c --app:lib --noMain -o:nlib.so nlib.nim</code> If I call the hi2 
function directly in Nim, it returns 900, perfectly. But if I call it from 
NodeJS via FFI:

<code> var ffi = require('ffi'); var lib = ffi.Library('./nlib.so', { 'hi2' : [ 
"int", ["string"] ] }); console.log(lib.hi2("hey"));</code> I get a 
<code>Segmentation fault (core dumped)</code>

Reply via email to