Nim icon indicating copy to clipboard operation
Nim copied to clipboard

Document isMainModule and appType for libraries

Open yglukhov opened this issue 4 years ago • 3 comments

# foo.nim
when isMainModule: echo "hi from foo"
# bar.nim
import dynlib
when isMainModule: echo "hi from bar"
doAssert(not loadLib("./libfoo.so").isNil)
nim c --app:lib foo
nim c -r bar

Output:

hi from bar
hi from foo

Expected output:

hi from bar

Note: I'm not sure it's an issue, but I'm getting a lot of questions about it in nimpy.

yglukhov avatar Mar 24 '21 10:03 yglukhov

Works as expected. We can improve the documentation and mention appType == "lib" and similar.

Araq avatar Mar 24 '21 12:03 Araq

@Araq Can you explain how to use appType == "lib" to make the example work?

ringabout avatar Mar 29 '21 09:03 ringabout

@xflywind when isMainModule and appType != "lib" I guess

ghost avatar Mar 29 '21 09:03 ghost