OGeek|极客世界-中国程序员成长平台

标题: CodeRunner 2 中的 C# 汇编 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:05
标题: CodeRunner 2 中的 C# 汇编

我正在使用 CodeRunner 2 (2.0.3),我无法在 C# 中编译代码。我收到警告:

/Users/Username/Library/Application Support/CodeRunner/Languages/C#.crLanguage/Scripts/compile.sh: line 25: gmcs: command not found

In order to run C# code, you need to have Mono installed. You can get it at http://mono-project.com

我安装了Mono ,我安装了Xamarin Studio并通过它进行了尝试。一些基本的东西有效,所以我知道Mono在那儿。我已经重新启动了我的计算机,重新启动了 CodeRunner 等。我在其他 StackOverflow 答案中做了一些事情,但仍然无法正常工作。我正在尝试从 THIS 运行一个简单的 URL 请求。例子。任何帮助表示赞赏。

提前谢谢你!

~解决了~ 谢谢 @clay-fowler

1. 打开 CodeRunner

2.将语言设置为C#

3.粘贴:

using System;
class Untitled
{
    static void Main(string[] args)
    {
        Console.Write ("Hello");
    }
}

4. 转到 CodeRunner -> 首选项 -> 语言 -> C#

5.在设置选项卡下,点击编辑脚本...

6. 将 gmcs 更改为 mcs(第 25 行)

7. 现在应该如下所示:

compname=`echo "$CR_FILENAME" | sed 's/\(.*\)\..*/\1/'`.exe
mcs "$CR_FILENAME" "${@:1}"
status=$?
if [ $status -eq 0 ]
then
echo $compname
exit 0
elif [ $status -eq 127 ]
then
echo -e "\nIn order to run C# code, you need to have Mono installed. You can get it at http://mono-project.com"
fi
exit $status

8.运行程序



Best Answer-推荐答案


这个错误意味着 CodeRunner 找不到 Mono 的二进制文件之一,它应该在你的 $PATH 上找到它:

gmcs: command not found

gmcs 是 Mono C# 编译器,但它是旧版本的旧名称,而不是当前发布的版本。现代 Mono 总是使用名为“mcs”的编译器。 gmcs 应该只是一个运行 mcs 以实现向后兼容性的 shell 脚本。它也是从/usr/bin 到它真正存在的/Library/Frameworks 的符号链接(symbolic link)。像这样:

/usr/bin/gmcs -> /Library/Frameworks/Mono.framework/Commands/gmcs

但是,在最近的一些 Mono 发行版中,这并没有在 Mac OS X 上正确部署。就我而言,/Library/Frameworks/Mono.framework/Commands/gmcs 不存在!也许对你来说也是。

因此,为了简单地解决这个问题并让事情自己运行,您可能只想将符号链接(symbolic link)更改为指向 mcs?

sudo ln -s /usr/bin/gmcs /Library/Frameworks/Mono.framework/Commands/mcs

这有点难看,会使您的系统变脏。只修改 CodeRunner 的 compile.sh 以使用 mcs 而不是 gmcs 就不会那么难看了。这不是完全等效的,因为 gmcs shell 脚本实际上使用一些可选参数调用 mcs,使其表现得像一个旧的编译器,但对于你做 CodeRunner 东西的情况,它可能是无害的。

关于CodeRunner 2 中的 C# 汇编,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32144847/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4