Unknown type `scopt.OParser$` when compiling to Native - Is scopt enabled for Scala Native?

I am starting a small Scala Native command line project where I try to use scopt for the CLI parsing.

I have noticed that another Sacla Native project (scalals) uses scopt as well.

However when I try to compile my project as Scala Native project, I get an “Unknown type scopt.OParser$” error. Here some, hopefully relevant, bits of the stack trace:

[error] Unknown type scopt.OParser$, referenced from:
         method cztools.Main$.main(java.lang.String[]): scala.runtime.BoxedUnit at CzDiff.scala:26
  static method cztools.Main.main(java.lang.String[]): scala.runtime.BoxedUnit at CzDiff.scala:25

...

Exception in thread "main" [info] Total (1124 ms)
scala.scalanative.linker.LinkingException: Unreachable symbols found after classloading run. It can happen when using dependencies not cross-compiled for Scala Native or not yet ported JDK definitions.
        at scala.scalanative.build.ScalaNative$.$anonfun$withReachabilityPostprocessing$3(ScalaNative.scala:94)
        at scala.concurrent.Future.$anonfun$flatMap$1(Future.scala:307)

...

So I wonder, is scopt indeed usable under Scala Native? (scalals seems to compile fine to Native.)

Or are there portions of scopt which are not Native compatible?

Also, I use Scala CLI` as build tool, does this possibly stuff up the Native compile?

Thanks for pointers!

Scopt is cross published for Native so probably https://youforgotapercentagesignoracolon.com/

2 Likes

Thanks for chiming in @WojciechMazur.

I have the following in my project.scala:

//> using scala "3.4.2"
//> using options "-indent", "-rewrite"

//> using dep "com.github.scopt::scopt:4.1.0"

So I will try the suggestion from https://youforgotapercentagesignoracolon.com. :slight_smile:

However, here a strange tidbit I have discovered since:

  • On my Intel MacBook the native compile finishes without problems with the current directives (one colon before the version).
  • Only on my M2 Mac Mini the native compile with the current directives throws the error listed in the original post!

I will report back when I am again at my M2 Mac and change the directives to two colons!

The suggestion from https://youforgotapercentagesignoracolon.com works perfectly!

Thanks, @WojciechMazur, for pointing me there!

2 Likes