Search code examples
c#iosxamarinmonocoderunner

C# Assembly in CodeRunner 2


I am using CodeRunner 2 (2.0.3) and I can not compile code in C#. I get the warning:

/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

I installed Mono, I installed Xamarin Studio and tried it through that as well. Some basic things work so I know Mono is there. I have restarted my computer, restarted CodeRunner, etc. I have done a few things in other StackOverflow answers and still doesn't work. I am attempting to run a simple URL request from THIS example. Any help is appreciated.

Thank you in advance!

~ SOLVED ~ Thank you @clay-fowler

1. Open CodeRunner

2. Set language to C#

3. Paste in:

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

4. Go to CodeRunner -> Preferences -> Languages -> C#

5. Under the Settings tab, click Edit Script...

6. Change gmcs to mcs (line 25)

7. Should now look like:

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. Run the program


Solution

  • This error means that CodeRunner can't find one of Mono's binaries, which it ought to be finding on your $PATH:

    gmcs: command not found
    

    gmcs is the Mono C# compiler, but it's an old name for an older version of it than what currently ships. Modern Mono always uses the compiler called "mcs". gmcs should simply be a shell script that runs mcs for backward compatibility. It is also a symlink from /usr/bin to /Library/Frameworks where it really lives. Like this:

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

    However, on some recent Mono distributions, this isn't getting deployed correctly on Mac OS X. In my case, /Library/Frameworks/Mono.framework/Commands/gmcs does not exist! Maybe for you, too.

    Therefore, to simply workaround this and get things running yourself, you might want to simply change the symlink to point at mcs?

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

    That's kind of ugly and makes your system dirty. It would be less ugly to just modify CodeRunner's compile.sh to use mcs instead of gmcs. This isn't exactly equivalent, since the gmcs shell script actually invokes mcs with some optional arguments that make it behave like an older compiler, but for your case of doing CodeRunner stuff it's probably harmless.