Kotlin compiler cannot find imports


My main.kt file looks like this:

import speech.Hi

fun main(args: Array<String>){
   val sayHello = Hi()
   val message = sayHello.speak() 

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.

What am I doing wrong?


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.


My file structure looks like this:

I’ve been running kotlinc main.kt and kotlcinc main.kt -cp speech without any luck.


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.


You need to run “kotlinc src”.


Yes, it has a declaration for the speech package.


When I run kotlinc src, I don’t get any output, however, it does compile without errors.


i also get same error
i already try kotlinc src but still have same error