* ref #19830; multiple definition of in Nim generated static libraries * fix compile errors
This commit is contained in:
parent
caf6aff06b
commit
0189122d4f
1 changed files with 18 additions and 18 deletions
|
|
@ -1323,7 +1323,7 @@ proc getSomeInitName(m: BModule, suffix: string): Rope =
|
||||||
proc getInitName(m: BModule): Rope =
|
proc getInitName(m: BModule): Rope =
|
||||||
if sfMainModule in m.module.flags:
|
if sfMainModule in m.module.flags:
|
||||||
# generate constant name for main module, for "easy" debugging.
|
# generate constant name for main module, for "easy" debugging.
|
||||||
result = rope"NimMainModule"
|
result = rope(m.config.nimMainPrefix) & rope"NimMainModule"
|
||||||
else:
|
else:
|
||||||
result = getSomeInitName(m, "Init000")
|
result = getSomeInitName(m, "Init000")
|
||||||
|
|
||||||
|
|
@ -1356,35 +1356,35 @@ proc genMainProc(m: BModule) =
|
||||||
preMainCode.add("\tinitStackBottomWith_actual((void *)&inner);\L")
|
preMainCode.add("\tinitStackBottomWith_actual((void *)&inner);\L")
|
||||||
preMainCode.add("\t(*inner)();\L")
|
preMainCode.add("\t(*inner)();\L")
|
||||||
else:
|
else:
|
||||||
preMainCode.add("\tPreMain();\L")
|
preMainCode.add("\t$1PreMain();\L" % [rope m.config.nimMainPrefix])
|
||||||
|
|
||||||
|
var posixCmdLine: Rope
|
||||||
|
if optNoMain notin m.config.globalOptions:
|
||||||
|
posixCmdLine.add "\tN_LIB_PRIVATE int cmdCount;\L"
|
||||||
|
posixCmdLine.add "\tN_LIB_PRIVATE char** cmdLine;\L"
|
||||||
|
posixCmdLine.add "\tN_LIB_PRIVATE char** gEnv;\L"
|
||||||
|
|
||||||
const
|
const
|
||||||
# not a big deal if we always compile these 3 global vars... makes the HCR code easier
|
|
||||||
PosixCmdLine =
|
|
||||||
"N_LIB_PRIVATE int cmdCount;$N" &
|
|
||||||
"N_LIB_PRIVATE char** cmdLine;$N" &
|
|
||||||
"N_LIB_PRIVATE char** gEnv;$N"
|
|
||||||
|
|
||||||
# The use of a volatile function pointer to call Pre/NimMainInner
|
# The use of a volatile function pointer to call Pre/NimMainInner
|
||||||
# prevents inlining of the NimMainInner function and dependent
|
# prevents inlining of the NimMainInner function and dependent
|
||||||
# functions, which might otherwise merge their stack frames.
|
# functions, which might otherwise merge their stack frames.
|
||||||
|
|
||||||
PreMainVolatileBody =
|
PreMainVolatileBody =
|
||||||
"\tvoid (*volatile inner)(void);$N" &
|
"\tvoid (*volatile inner)(void);$N" &
|
||||||
"\tinner = PreMainInner;$N" &
|
"\tinner = $3PreMainInner;$N" &
|
||||||
"$1" &
|
"$1" &
|
||||||
"\t(*inner)();$N"
|
"\t(*inner)();$N"
|
||||||
|
|
||||||
PreMainNonVolatileBody =
|
PreMainNonVolatileBody =
|
||||||
"$1" &
|
"$1" &
|
||||||
"\tPreMainInner();$N"
|
"\t$3PreMainInner();$N"
|
||||||
|
|
||||||
PreMainBodyStart = "$N" &
|
PreMainBodyStart = "$N" &
|
||||||
"N_LIB_PRIVATE void PreMainInner(void) {$N" &
|
"N_LIB_PRIVATE void $3PreMainInner(void) {$N" &
|
||||||
"$2" &
|
"$2" &
|
||||||
"}$N$N" &
|
"}$N$N" &
|
||||||
PosixCmdLine &
|
"$4" &
|
||||||
"N_LIB_PRIVATE void PreMain(void) {$N"
|
"N_LIB_PRIVATE void $3PreMain(void) {$N"
|
||||||
|
|
||||||
PreMainBodyEnd =
|
PreMainBodyEnd =
|
||||||
"}$N$N"
|
"}$N$N"
|
||||||
|
|
@ -1395,21 +1395,21 @@ proc genMainProc(m: BModule) =
|
||||||
MainProcsWithResult =
|
MainProcsWithResult =
|
||||||
MainProcs & ("\treturn $1nim_program_result;$N")
|
MainProcs & ("\treturn $1nim_program_result;$N")
|
||||||
|
|
||||||
NimMainInner = "N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {$N" &
|
NimMainInner = "N_LIB_PRIVATE N_CDECL(void, $5NimMainInner)(void) {$N" &
|
||||||
"$1" &
|
"$1" &
|
||||||
"}$N$N"
|
"}$N$N"
|
||||||
|
|
||||||
NimMainVolatileBody =
|
NimMainVolatileBody =
|
||||||
"\tvoid (*volatile inner)(void);$N" &
|
"\tvoid (*volatile inner)(void);$N" &
|
||||||
"$4" &
|
"$4" &
|
||||||
"\tinner = NimMainInner;$N" &
|
"\tinner = $5NimMainInner;$N" &
|
||||||
"$2" &
|
"$2" &
|
||||||
"\t(*inner)();$N"
|
"\t(*inner)();$N"
|
||||||
|
|
||||||
NimMainNonVolatileBody =
|
NimMainNonVolatileBody =
|
||||||
"$4" &
|
"$4" &
|
||||||
"$2" &
|
"$2" &
|
||||||
"\tNimMainInner();$N"
|
"\t$5NimMainInner();$N"
|
||||||
|
|
||||||
NimMainProcStart =
|
NimMainProcStart =
|
||||||
"N_CDECL(void, $5NimMain)(void) {$N"
|
"N_CDECL(void, $5NimMain)(void) {$N"
|
||||||
|
|
@ -1489,9 +1489,9 @@ proc genMainProc(m: BModule) =
|
||||||
else: ropecg(m, "\t#initStackBottomWith((void *)&inner);$N", [])
|
else: ropecg(m, "\t#initStackBottomWith((void *)&inner);$N", [])
|
||||||
inc(m.labels)
|
inc(m.labels)
|
||||||
if m.config.selectedGC notin {gcNone, gcArc, gcOrc}:
|
if m.config.selectedGC notin {gcNone, gcArc, gcOrc}:
|
||||||
appcg(m, m.s[cfsProcs], PreMainBodyStart & PreMainVolatileBody & PreMainBodyEnd, [m.g.mainDatInit, m.g.otherModsInit])
|
appcg(m, m.s[cfsProcs], PreMainBodyStart & PreMainVolatileBody & PreMainBodyEnd, [m.g.mainDatInit, m.g.otherModsInit, m.config.nimMainPrefix, posixCmdLine])
|
||||||
else:
|
else:
|
||||||
appcg(m, m.s[cfsProcs], PreMainBodyStart & PreMainNonVolatileBody & PreMainBodyEnd, [m.g.mainDatInit, m.g.otherModsInit])
|
appcg(m, m.s[cfsProcs], PreMainBodyStart & PreMainNonVolatileBody & PreMainBodyEnd, [m.g.mainDatInit, m.g.otherModsInit, m.config.nimMainPrefix, posixCmdLine])
|
||||||
|
|
||||||
if m.config.target.targetOS == osWindows and
|
if m.config.target.targetOS == osWindows and
|
||||||
m.config.globalOptions * {optGenGuiApp, optGenDynLib} != {}:
|
m.config.globalOptions * {optGenGuiApp, optGenDynLib} != {}:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue