How do one print to the `stderr` in K/N?
# kotlin-native
m
How do one print to the
stderr
in K/N?
o
Copy code
import platform.posix.*

fun main(args: Array<String>) {
   fprintf(stderr, "Hi\n")
}
m
Thanks! Any way to do that in platform independend way like
print
(e.g.
printerr
)?
o
It is relatively platform-independent (will work on Linux mac and Windows)
f
How about the other kind of platform-independent (jvm/js/native)?
o
not sure what would it mean on JS for example, and in general it likely shall be something in target dependent portability layer
g
On JS it will be
console.error()
,
System.err
on JVM
o
Generally K/N is not trying to abstract out platform facilities, unlike Java, so we not planning to provide portable methods for doing everything in stock libraries, although nothing prevents development of abstraction layers like that externally.
j
Hi, thanks for the tip. I just had to change
stderr
to
__stderrp
(did take me a while 🙂 )
o
maybe makes sense to contribute into .def file for your platform with wrapper making
stderr
available under expected name, see similar logic for zlib: https://github.com/JetBrains/kotlin-native/blob/0fed84a2cdbf6685b54b5059dc03853b954b9456/platformLibs/src/platform/osx/zlib.def#L31