Hello, I am trying to port a linux native binary f...
# getting-started
a
Hello, I am trying to port a linux native binary from .kt file. I could not find kotlin-native package in snap/apt in ubuntu. There is only kotlinc. Any idea how to quickly generate a native binary?
e
https://kotlinlang.org/docs/native-command-line-compiler.html but you should almost certainly just use Gradle instead
I was able to build simple hello world. But I can not import libraries as I could do with regular Kotlin builds. I am new to gradle(Have been using Intellij). When I try to build with a simple inbuilt lib, it fails
import java.awt.GraphicsEnvironment
fun main() {
_println_("Hello nativeS")
}
j
You won't be able to use Java APIs in Kotlin native, it doesn't run on the JVM, there is no JRE. If you want to run JVM-based programs natively, consider GraalVM maybe
a
Got it. Thanks for mentioning. Otherwise it would have cost me lot of time to self realize. I will explore GraaIVM. btw I was trying to port simple utility to turnoff display when required https://raw.githubusercontent.com/arunmummidi/kotlin-tools/main/turnOffDisplay.kt
e
as much as I like Kotlin, there's no reason to use Kotlin for that, it's just wrapping a command line tool
if you really want to make deployment easy, turn it into a
.main.kts
script that'll work anywhere a
kotlinc
binary is available
👍 1
a
yeah, it does dumb stuff. But it is to build some kotlin muscle for a noob. Not for prod use though ;)
k
By the way, I wouldn't use
assert
in that context.
assert
is meant only for debugging or confirming code correctness and only turned on if you explicitly enable it on the command line. In your situation, I would use
check
.
e
technically Kotlin's
assert
function is a bit different than Java's
assert
statement in that the condition is always evaluated by default (
-Xassertions=legacy
), instead of following the JVM's
-ea
, although the actual
throw AssertionError
are still controlled by
-ea
by default. given how tricky it is, I would also suggest to avoid
assert
which was already a mostly-bad idea in Java