【问题标题】:How to troubleshoot scala3 program compilation error on Windows 7如何解决 Windows 7 上的 scala3 程序编译错误
【发布时间】:2021-11-30 02:34:38
【问题描述】:

我已经在我的 Windows 7 PC 上安装了 scala 编译器和 repl:

bitsadmin /transfer cs-cli https://git.io/coursier-cli-windows-exe "%cd%\cs.exe"
cs install scala3-compiler
cs install scala3-repl

然后我从这个链接复制了一个 hello world 程序: https://docs.scala-lang.org/scala3/book/taste-hello-world.html

然后我尝试用 scalac 编译:

D:\projects\Coursera\scala\code\play>scalac Hello.scala
SetConsoleMode failed (is stdin a console?)
At line:29 char:10
+     throw <<<<  "SetConsoleMode failed (is stdin a console?)"
    + CategoryInfo          : OperationStopped: (SetConsoleMode ...din a console?):String) [], RuntimeException
    + FullyQualifiedErrorId : SetConsoleMode failed (is stdin a console?)

Hello.scala:1: error: expected start of definition
@main def hello = println("Hello, world!")
  ^
1 error

D:\projects\Coursera\scala\code\play>

我做错了什么?我该如何构建这个程序?

我正在运行 Windows 7 Professional 64 位。

更新信息:

D:\projects\Coursera\scala\code\play>scalac -version
SetConsoleMode failed (is stdin a console?)
At line:29 char:10
+     throw <<<<  "SetConsoleMode failed (is stdin a console?)"
    + CategoryInfo          : OperationStopped: (SetConsoleMode ...din a console?):String) [], RuntimeException
    + FullyQualifiedErrorId : SetConsoleMode failed (is stdin a console?)

Scala compiler version 2.13.6 -- Copyright 2002-2021, LAMP/EPFL and Lightbend, Inc.

D:\projects\Coursera\scala\code\play>scala3-compiler Hello.scala
SetConsoleMode failed (is stdin a console?)
At line:29 char:10
+     throw <<<<  "SetConsoleMode failed (is stdin a console?)"
    + CategoryInfo          : OperationStopped: (SetConsoleMode ...din a console?):String) [], RuntimeException
    + FullyQualifiedErrorId : SetConsoleMode failed (is stdin a console?)

D:\projects\Coursera\scala\code\play>dir
 Volume in drive D is DATAPART1
 Volume Serial Number is A23F-1A44

 Directory of D:\projects\Coursera\scala\code\play

25/06/2021  21:55    <DIR>          .
25/06/2021  21:55    <DIR>          ..
25/06/2021  21:55               758 Hello$package$.class
25/06/2021  21:55               267 Hello$package.class
25/06/2021  21:55               567 Hello$package.tasty
25/06/2021  21:55               912 hello.class
25/06/2021  17:18                44 Hello.scala
25/06/2021  21:55               474 hello.tasty
               6 File(s)          3,022 bytes
               2 Dir(s)  522,054,057,984 bytes free

D:\projects\Coursera\scala\code\play>scala hello
SetConsoleMode failed (is stdin a console?)
At line:29 char:10
+     throw <<<<  "SetConsoleMode failed (is stdin a console?)"
    + CategoryInfo          : OperationStopped: (SetConsoleMode ...din a console?):String) [], RuntimeException
    + FullyQualifiedErrorId : SetConsoleMode failed (is stdin a console?)

Exception in thread "main" java.lang.NoClassDefFoundError: 
scala/util/CommandLineParser$ParseError
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:398)
        at scala.reflect.internal.util.RichClassLoader$.$anonfun$tryClass$extension$1(ScalaClassLoader.scala:47)
        at scala.util.control.Exception$Catch.$anonfun$opt$1(Exception.scala:245)
    at scala.util.control.Exception$Catch.apply(Exception.scala:227)
    at scala.util.control.Exception$Catch.opt(Exception.scala:245)
    at scala.reflect.internal.util.RichClassLoader$.tryClass$extension(ScalaClassLoader.scala:47)
    at scala.reflect.internal.util.RichClassLoader$.run$extension(ScalaClassLoader.scala:43)
    at scala.tools.nsc.CommonRunner.run(ObjectRunner.scala:30)
    at scala.tools.nsc.CommonRunner.run$(ObjectRunner.scala:28)
    at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45)
    at scala.tools.nsc.CommonRunner.runAndCatch(ObjectRunner.scala:37)
    at scala.tools.nsc.CommonRunner.runAndCatch$(ObjectRunner.scala:36)
    at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:70)
    at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:91)
    at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:103)
    at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:108)
    at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at coursier.bootstrap.launcher.a.a(Unknown Source)
    at coursier.bootstrap.launcher.Launcher.main(Unknown Source)
Caused by: java.lang.ClassNotFoundException: 
scala.util.CommandLineParser$ParseError
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 24 more

D:\projects\Coursera\scala\code\play>

试图以 scala3-compiler hello 运行

D:\projects\Coursera\scala\code\play>scala3-compiler hello
SetConsoleMode failed (is stdin a console?)
At line:29 char:10
+     throw <<<<  "SetConsoleMode failed (is stdin a console?)"
    + CategoryInfo          : OperationStopped: (SetConsoleMode ...din a console?):String) [], RuntimeException
    + FullyQualifiedErrorId : SetConsoleMode failed (is stdin a console?)

not found: hello
1 error found

【问题讨论】:

  • 你确定scalacScala 3 编译器吗?尝试调用scalac -version 进行确认,我猜它实际上是 Scala 2 编译器,而使用 Scala 3 你应该这样做scala3-compiler Hello.scala
  • 看来使用scala3-compiler命令是可行的,现在我相信运行代码的方式也应该是scala3-compiler Hello
  • @LuisMiguelMejíaSuárez 不确定,因为我似乎无法运行该程序 - 见上文。
  • 再次使用2.13 编译器运行Scala 3 程序,尝试使用scala3-compiler Hello 运行它。
  • @LuisMiguelMejíaSuárez - 试过了 - 见上文。 - 还尝试了 scala3-compiler Hello - 结果相同。

标签: scala compiler-errors


【解决方案1】:
scala3-compiler hello.scala
scala3 Hello 

或 作为 scala-lang 的示例,包含注释 @main 所以

def hello (hello is the class in the compiler output) 

所以运行它的命令:

scala3 hello

程序会在cmd中运行错误

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 2013-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-11
  • 1970-01-01
相关资源
最近更新 更多