-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multiple definition of
in Nim generated static libraries
#19830
Comments
multiple definition of
Nim generated static librariesmultiple definition of
in Nim generated static libraries
You have to use the |
The thing is that only |
This issue is currently blocking progress for me, any way to get it prioritized? |
Maybe this will help, works on Windows. On Linux however, diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index ad59b759f..bb91b8624 100644
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -1322,7 +1322,7 @@ proc getSomeInitName(m: BModule, suffix: string): Rope =
proc getInitName(m: BModule): Rope =
if sfMainModule in m.module.flags:
# generate constant name for main module, for "easy" debugging.
- result = rope"NimMainModule"
+ result = rope m.config.nimMainPrefix & "NimMainModule"
else:
result = getSomeInitName(m, "Init000")
@@ -1351,11 +1351,11 @@ proc genMainProc(m: BModule) =
preMainCode.add("\tvoid* rtl_handle;\L")
preMainCode.add(loadLib("rtl_handle", "nimGC_setStackBottom"))
preMainCode.add(hcrGetProcLoadCode(m, "nimGC_setStackBottom", "nimrtl_", "rtl_handle", "nimGetProcAddr"))
- preMainCode.add("\tinner = PreMain;\L")
+ preMainCode.add("\tinner = " & m.config.nimMainPrefix & "PreMain;\L")
preMainCode.add("\tinitStackBottomWith_actual((void *)&inner);\L")
preMainCode.add("\t(*inner)();\L")
else:
- preMainCode.add("\tPreMain();\L")
+ preMainCode.add("\t" & m.config.nimMainPrefix & "PreMain();\L")
const
# not a big deal if we always compile these 3 global vars... makes the HCR code easier
@@ -1370,20 +1370,20 @@ proc genMainProc(m: BModule) =
PreMainVolatileBody =
"\tvoid (*volatile inner)(void);$N" &
- "\tinner = PreMainInner;$N" &
+ "\tinner = $3PreMainInner;$N" &
"$1" &
"\t(*inner)();$N"
PreMainNonVolatileBody =
"$1" &
- "\tPreMainInner();$N"
+ "\t$3PreMainInner();$N"
PreMainBodyStart = "$N" &
- "N_LIB_PRIVATE void PreMainInner(void) {$N" &
+ "N_LIB_PRIVATE void $3PreMainInner(void) {$N" &
"$2" &
"}$N$N" &
PosixCmdLine &
- "N_LIB_PRIVATE void PreMain(void) {$N"
+ "N_LIB_PRIVATE void $3PreMain(void) {$N"
PreMainBodyEnd =
"}$N$N"
@@ -1394,21 +1394,21 @@ proc genMainProc(m: BModule) =
MainProcsWithResult =
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" &
"}$N$N"
NimMainVolatileBody =
"\tvoid (*volatile inner)(void);$N" &
"$4" &
- "\tinner = NimMainInner;$N" &
+ "\tinner = $5NimMainInner;$N" &
"$2" &
"\t(*inner)();$N"
NimMainNonVolatileBody =
"$4" &
"$2" &
- "\tNimMainInner();$N"
+ "\t$5NimMainInner();$N"
NimMainProcStart =
"N_CDECL(void, $5NimMain)(void) {$N"
@@ -1488,9 +1488,9 @@ proc genMainProc(m: BModule) =
else: ropecg(m, "\t#initStackBottomWith((void *)&inner);$N", [])
inc(m.labels)
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])
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])
if m.config.target.targetOS == osWindows and
m.config.globalOptions * {optGenGuiApp, optGenDynLib} != {}: |
This is nice for now but we really need symbol isolation otherwise it's impossible to create C ABIs for Nim libraries because any two will clash on any common parts of their respective dependency tree including the standard library. It might be worth generalizing |
This also seems promising, I had no idea you could use |
imo When using |
I discovered that if you can use the |
Expand `--nimMainPrefix` semantics to include prefixing these symbols for the C, C++ and ObjC backends: * `cmdCount` * `cmdLine` * `gEnv` * `PreMain` * `PreMainInner` * `NimMainInner` * `NimMainModule` Fixes nim-lang#15955 Fixes nim-lang#19830
This works now. |
Hello! I'm having similar issue trying to build a static lib in Nim and then use an other Nim script to import the lib. (It's for testing only). I got similar issue and add |
…braries (nim-lang#19934) * ref nim-lang#19830; multiple definition of in Nim generated static libraries * fix compile errors
It does not work now.
|
This is NOT the error mentioned in the issue. The error log showed the compiler was |
I know, but earlier I used this method to solve this issue as well, but now it doesn't work. Also, nim always calls clang as a linker on my machine. if this flag is not available, how should I resolve this issue. |
Example
lib_a.nim
lib_b.nim
app.c
Current Output
Expected Output
Possible Solution
NimMainModule_source_name_qwerty12345()
instead ofNimMainModule()
cmdCount_source_name_qwerty12345()
instead ofcmdCount()
Additional Information
Tested with
--mm:arc
--mm:orc
--mm:refc
--mm:none
+ with the--header
optionThe text was updated successfully, but these errors were encountered: