visibility.nim 891 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. discard """
  2. output: ""
  3. """
  4. const LibName {.used.} =
  5. when defined(windows):
  6. "visibility.dll"
  7. elif defined(macosx):
  8. "libvisibility.dylib"
  9. else:
  10. "libvisibility.so"
  11. when compileOption("app", "lib"):
  12. var
  13. bar {.exportc.}: int
  14. thr {.exportc, threadvar.}: int
  15. proc foo() {.exportc.} = discard
  16. var
  17. exported {.exportc, dynlib.}: int
  18. exported_thr {.exportc, threadvar, dynlib.}: int
  19. proc exported_func() {.exportc, dynlib.} = discard
  20. elif isMainModule:
  21. import dynlib
  22. let handle = loadLib(LibName)
  23. template check(sym: untyped) =
  24. const s = astToStr(sym)
  25. if handle.symAddr(s) != nil:
  26. echo s, " is exported"
  27. template checkE(sym: untyped) =
  28. const s = astToStr(sym)
  29. if handle.symAddr(s) == nil:
  30. echo s, " is not exported"
  31. check foo
  32. check bar
  33. check thr
  34. checkE exported
  35. checkE exported_thr
  36. checkE exported_func