Skip to content
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

[minor] strdefine value wrongly treated as its default value in some pragmas #12929

Closed
timotheecour opened this issue Dec 19, 2019 · 2 comments · Fixed by #22575
Closed

[minor] strdefine value wrongly treated as its default value in some pragmas #12929

timotheecour opened this issue Dec 19, 2019 · 2 comments · Fixed by #22575

Comments

@timotheecour
Copy link
Member

timotheecour commented Dec 19, 2019

in const mylib {.strdefine.} = "", mylib is treated as empty in {.dynlib: mylib.} even if it's set on cmd line with -d:mylib:bar;
a use case for it came from here #12922 (comment)

I'm marking this as [minor] because there is a workaround, see below

Example

const mylib {.strdefine.} = ""
proc test01() {.importc, dynlib: mylib.}

self-contained full example:
nim c -r -d:mylib:/tmp/libD20191219T022227.dylib main.nim

when defined(timn_D20191219T022227):
  proc test01() {.exportc.} = echo "ok2"
else:
  import std/[strformat,os]
  const mylib {.strdefine.} = ""
  const nim = getCurrentCompilerExe()
  const file = currentSourcePath()
  static:
    let cmd = fmt"{nim} c -d:timn_D20191219T022227 --app:lib -o:{mylib} {file}"
    echo cmd
    let (output, exitCode) = gorgeEx cmd
    doAssert exitCode == 0, output

  when true:
    proc test01() {.importc, dynlib: mylib.} # BUG
  else:
    # workaround: this would work:
    const mylib2 = mylib
    proc test01() {.importc, dynlib: mylib2.}

  proc main()=
    test01()
  main()

Current Output

could not load:
compile with -d:nimDebugDlOpen for more information

Expected Output

works

Additional Information

recent devel 5848f00

workaround

# instead of:
proc test01() {.importc, dynlib: mylib.}

# use option1
const mylib2 = mylib
proc test01() {.importc, dynlib: mylib2.}

# use option2
proc test01() {.importc, dynlib: static(mylib).}
@Clyybber
Copy link
Contributor

To clarify, it uses the default value of const mylib {.strdefine.} = "" even when overridden via -d:mylib:/tmp/somelib.so which in your example is "".

timotheecour added a commit to timotheecour/Nim that referenced this issue Apr 14, 2020
@timotheecour timotheecour changed the title [minor] strdefine value wrongly treated as empty in some pragmas [minor] strdefine value wrongly treated as its default value in some pragmas Apr 14, 2020
@timotheecour
Copy link
Member Author

indeed; reworded title and sent a PR to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants