kotlincmd

Kotlin Can't Run Basic App in CMD error unresolved reference


I was following Kotlin Tutorial

So I went to notepad++ and created

hello.kt

Contents of

hello.kt



fun main() {
    println("Hello, World!")
}

Next I opened cmd and typed:

    kotlinc hello.kt -include-runtime -d hello.jar

This is the output:

WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by com.intellij.util.containers.Unsafe
WARNING: Please consider reporting this to the maintainers of class com.intellij.util.containers.Unsafe
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release
hello.kt:4:5: error: unresolved reference 'println'.
    println("Hello, World!")
    ^^^^^^^

Please note I am not working in intellij idea. I am trying to run a basic kotlin standalone app and have correctly configured the path to kotlinc bin folder of kotlin-compiler-2.2.10.zip

All the other solutions and problems posted on stackoverflow are applicable to people working in intellij idea and I am not working in intellij idea. Please help me to get up and running in Windows terminal using the kotlin compiler only. On my Windows machine, I have jdk 24


Solution

  • I moved the kotlinc home folder from C:\Program Files\kotlinc\bin

    to C:\kotlinc\bin

    Next I deleted the kotlinc user environment variable and appended the new kotlinc home folder location to the Path system environment variable. It now works like a charm.