import speech.Hi
fun main(args: Array<String>){
val sayHello = Hi()
val message = sayHello.speak()
println(message)
}
When I run this in IntelliJ, it works just fine.
When I attempt to compile it with kotlinc and run it in the Windows command line on the other hand, it gives me an “unresolved reference” on my speech package.
How exactly you’re running the compiler? You need to give the entire directory containing your project source code as the argument to kotlinc. If you just give it a single file as an argument, it won’t be able to import any other files.
Does the Hi.kt file actually declare the package to be speech? Unlike Java, Kotlin is fine with classes not living in a directory that corresponds to its package.
Just struggled with the same problem and my solution was to run that way:
Download kotlin’s latest release from here: Releases · JetBrains/kotlin · GitHub - At the time of this post it was “v1.5.20” (the zip file to download is located at the bottom of the page)
Unzip “kotlin-compiler-1.5.20.zip” it in a place of your choice. Locate the bin folder and copy its path to your environment path (on Windows)
It should look something like this: your_download_location\kotlinc\bin
Open your system settings and edit the system environment variable called “PATH” by adding a new entry to it using the located path above - System environment path can be edited on Windows over: System Settings > System and Security > System > Advanced system setting > Environment variables…
Compile the program using the kotlin compiler command bellow by opening a terminal in the root of this project: