I am trying to build a static library using Nim and plan to use that lib in Nim and C applications.
I passed the --app:staticlib --noMain --header:myheader.h flags when building the nim file for the static library.
However, the static library can not be linked in a second Nim application due to stdlib_system.c. being generated for both the static library and the second nim aplication.
Therefore the linker will get lots of duplicate symbol errors like:
duplicate symbol _forAllChildren_yHFnLgI7q81iFxRlb3Iqlw in: /Volumes/dev/nimapp/src/stdlib_system.c.o /Volumes/dev/nimstaticlibrary/libnimstatic.a(stdlib_system.o) duplicate symbol _rawNewObj_BpNS5yt3b9cMOponsUKh8aw in: /Volumes/dev/nimapp/src/stdlib_system.c.o /Volumes/dev/nimstaticlibrary/libnimstatic.a(stdlib_system.o) duplicate symbol _rawNewString in: /Volumes/dev/nimapp/src/stdlib_system.c.o /Volumes/dev/nimstaticlibrary/libnimstatic.a(stdlib_system.o)
Moreover, functions like NimMain are generated in the static library C files even when using the --noMain flag (reported in this issue) also leading to linker errors like these:
duplicate symbol _NimMain in: /Volumes/dev/nimapp/src/main.c.o /Users/user/nimstaticlibrary/libnimstatic.a(main.o) duplicate symbol _PreMain in: /Volumes/dev/nimapp/src/main.c.o /Users/user/nimstaticlibrary/libnimstatic.a(main.o)
Same thing should happen when having multiple static libraries built with Nim and trying to link those with another app (written in C or Nim).
Is there any way to build a static library with Nim that can be linked in another Nim application without getting the duplicate symbols errors?