Rececently I saw some posts related with this topic, and then I viewed https://peterme.net/dynamic-libraries-in-nim.html, but there're still something not very clear.
So I started a test.
First, I went to lib/nim, using the command nim c -d:release lib/nimrtl.nim to generate libnimrtl.so, then moved it to the lib path of the system.
Also I wrote two files:
#test1.nim
proc f(x: int64) {.nimcall, exportc, dynlib.} =
echo "x = " & $x
cmopiled with nim c --mm:refc --app:lib --noMain -d:useNimRtl test1.nim, and
#test0.nim
proc f(x: int64) {.importc, nimcall, dynlib: "./libtest1.so".}
proc initModuleTest1() {.importc: "NimMain", dynlib: "./libtest1.so".}
initModuleTest1()
f(1)
compiled with nim c --mm:refc -d:useNimRtl test0.nim.
Output:
x = 1
I guess if I don't use -d:useNimRtl on both modules, there'll be two instances of GC, because the main module has one, and nimrtl creates another one.
Also I found that a segmentation fault can happen if all of the followings are true:
That's all.