I'm using Nim to create multiple static libraries which will be used in a C project. But every static library has it's *Main* functions and linking multiple libraries in the same project causes this error:
libA.a(@mlibB.nim.c.o): In function `NimMainInner':
@mlibB.nim.c:(.text+0x0): multiple definition of `NimMainInner'
and the same happens on PreMainInner, PreMain and NimMainModule.
I compile all the libraries in this way:
nim c -d:danger --opt:size --mm:orc --app:staticlib --no_main --header --nimMainPrefix:libA --out:libA.a a.nim
nim c -d:danger --opt:size --mm:orc --app:staticlib --no_main --header --nimMainPrefix:libB --out:libB.a b.nim
What else do I have to pass to the compiler to avoid this error?
No, I'm using 1.6.2:
$ nim -v
Nim Compiler Version 1.6.2 [Linux: amd64]
Compiled at 2021-12-17
Copyright (c) 2006-2021 by Andreas Rumpf
git hash: 9084d9bc02bcd983b81a4c76a05f27b9ce2707dd
active boot switches: -d:release
I try the "devel" branch and let you know. Thanks.
It is the same with this version:
$ ../Nim-devel/bin/nim -v
Nim Compiler Version 1.7.1 [Linux: amd64]
Compiled at 2022-03-23
Copyright (c) 2006-2022 by Andreas Rumpf
active boot switches: -d:release
This does indeed seem to be a bug, or at least something that hasn't been properly tested. IMO the --nimMainPrefix should apply to all the *Main* procedures (and probably initStackBottomWith as well, this would at least partially solve the issue. That being said most of the procedures generated for this seem to be related to the old GC, so maybe ARC/ORC should have it's own main initialization which just initialized globals and didn't do any of the rigamarole around stack bottom initialization.
Or maybe what we need is a way to prefix _every procedure with the module name or some other set thing, much like C libraries themselves seem to deal with this issue.