Errors running kotlin class from comd-line

hello everyone,

I’m trying to run a kotlin class from CLI(Kotlin command-line compiler | Kotlin Documentation), but I get some errors:

Can anyone help me to find out the problem??

Thanks to all,

Can you include the code you’re trying to compile?

Though tbh, this looks like a bug with the compiler. I’ve just briefly skimmed the docs, but using the -include-runtime flag should include Kotlin runtime library (which I assume is the same as the standard library?) so you should be able to use code from the standard library like println.

How did you install the compiler? Maybe it’s missing the runtime library, or something?

The code of my app is really simple @Skater901:

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


I download compiler from GitHub, I didn´t install it (I don’t know how to install it) Is it needed to install it??

Nope, looks like you did the steps correctly: https://kotlinlang.org/docs/command-line.html#manual-install

Tbh I’ve never used the command line compiler. Is there a reason you’re using it instead of IntelliJ? I don’t think I can help, unfortunately. :frowning:

1 Like

Thanks for you reply @Skater901.

There’s no any special reason for using command line compiler. Simply, in my old PC I don´t have enough RAM to install IntelliJ………… the message error is very confusing for me, definitively, I don’t understand the problem :thinking:

I don’t understand either, but my rough guess is that it can’t find the Kotlin standard library (which is where println() et al are defined). So I’d poke around and try to confirm that it came with the compiler and is where the compiler is likely to find it.

(The -include-runtime flag is related but slightly different, as that will include the standard library in the output jar. But even if it’s not doing that, the compiler will need access to it while compiling, in order to identify the correct classes and methods.)

1 Like

Hello again,

I’ve created build.gradle.kts file but I’m still with the same error :head_shaking_vertically:

Are you actually using Gradle?

Gradle requires gradle/gradle-wrapper.jar, and also a gradlew bash script (or gradlew.bat script for Windows). You then compile your code by invoking the gradlew script. ./gradlew compileKotlin.

Also you don’t need to include the Kotlin stdlib as a dependency; the Kotlin plugin automatically adds the stdlib as a dependency.

I don´t know anything about Gradle, I only use Gradle because docs recomend it: :

The ‘unresolved reference: println’ error in Kotlin typically arises when the Kotlin standard library is not properly included in your project. This issue can occur while using Gradle from the CLI if the configuration is incorrect or if the environment is not set up properly."

I get stack but i don´t know if I need to use Gradle. I don’t know about Gradle so I’d prefer not to use Gradle if there are another ways but I don’t know if there are more ways to find out the problem

if i don’t use Gradle, what more can I do ??

Oh, yeah I would ignore that. That’s talking about an error that can occur when you’re using Gradle. But you weren’t using Gradle, so that specific error is irrelevant to you. I would remove all Gradle stuff, just stick to having your code and the CLI compiler.

I’ll download the compiler myself and give it a go, see if I can get it working.

Ok, I was able to make it work with the latest compiler. I would say maybe there’s a bug in the specific compiler you downloaded. Download the latest version of the compiler (2.4.10) and try again.

BTW, you might not want to compile to a .jar file; if you omit the -d s1.jar, it’ll just compile it to a Java class file that you can run. You want to compile to a .jar file once you start having multiple files in your project.

1 Like

ok, many thanks @Skater901…thanksSkater901…thanks a lot for your help :melting_face:

2 Likes