Skip to content

Commit

Permalink
Fix #16937; --clib option pass library name to backend C compiler cor…
Browse files Browse the repository at this point in the history
…rectly (#19754)

* Fix 16937: Make --clib option works

* Make tests/compiler/tcmdlineclib.nim works from any current dir

* Try to fix link error on macosx

* Add a comment to tests/compiler/tcmdlineclib.nims

Co-authored-by: Clay Sweetser <[email protected]>
  • Loading branch information
demotomohiro and Varriount authored Sep 1, 2022
1 parent a95b639 commit 2a34d14
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
of "clib":
expectArg(conf, switch, arg, pass, info)
if pass in {passCmd2, passPP}:
conf.cLinkedLibs.add processPath(conf, arg, info).string
conf.cLinkedLibs.add arg
of "header":
if conf != nil: conf.headerFile = arg
incl(conf.globalOptions, optGenIndex)
Expand Down
2 changes: 2 additions & 0 deletions tests/compiler/samplelib.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Sample library used by tcmdlineclib.nim
proc test(): int {.cdecl, exportc, dynlib.} = 123
3 changes: 3 additions & 0 deletions tests/compiler/tcmdlineclib.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
proc test(): int {.importc, cdecl.}

doAssert test() == 123
10 changes: 10 additions & 0 deletions tests/compiler/tcmdlineclib.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os

selfExec "c --app:lib " & (projectDir() / "samplelib.nim")
switch("clibdir", projectDir())
--clib:samplelib

# Make test executable can load sample shared library.
# `-rpath` option doesn't work and ignored on Windows.
# But the dll file in same directory as executable file is loaded.
switch("passL", "-Wl,-rpath," & projectDir())

0 comments on commit 2a34d14

Please sign in to comment.