diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 2d4e70420b..7b71239e96 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -2497,12 +2497,13 @@ proc updateCachedModule(m: BModule) = addFileToCompile(m.config, cf) proc generateLibraryDestroyGlobals(graph: ModuleGraph; m: BModule; body: PNode; isDynlib: bool): PSym = - let procname = getIdent(graph.cache, "NimDestroyGlobals") + let prefixedName = m.config.nimMainPrefix & "NimDestroyGlobals" + let procname = getIdent(graph.cache, prefixedName) result = newSym(skProc, procname, m.idgen, m.module.owner, m.module.info) result.typ = newProcType(m.module.info, m.idgen, m.module.owner) result.typ.callConv = ccCDecl incl result.flags, sfExportc - result.loc.snippet = "NimDestroyGlobals" + result.loc.snippet = prefixedName if isDynlib: incl(result.loc.flags, lfExportLib) diff --git a/doc/backends.md b/doc/backends.md index 6751703430..a8db83fb59 100644 --- a/doc/backends.md +++ b/doc/backends.md @@ -249,7 +249,7 @@ which will likely make your program crash at runtime. The name `NimMain` can be influenced via the `--nimMainPrefix:prefix` switch. Use `--nimMainPrefix:MyLib` and the function to call is named `MyLibNimMain`. -When compiling to static or dynamic libraries, they don't call destructors of global variables as normal Nim programs would do. A C API `NimDestroyGlobals` is provided to call these global destructors. +When compiling to static or dynamic libraries, they don't call destructors of global variables as normal Nim programs would do. A C API `NimDestroyGlobals` is provided to call these global destructors. It is influenced by the `--nimMainPrefix:prefix` switch, too. ### Nim invocation example from C