Run the. NET program on Mac OS X with your own compiled CORECLR

Source: Internet
Author: User
Tags mscorlib

When it was difficult to compile CORECLR on Mac OS X yesterday (see the attempt to compile CoreCLR source code on Mac OS X), it was later discovered that the puzzle was solved by the man-in-the-@kangaroo, and even CoreCLR's Microsoft developers were surprised (see #105).

@kangaroo this is awesome! Thank much for doing it! I ' ll start reviewing it in the morning.

Today, it is found that the version that can be compiled on OS X @kangaroo modified has been incorporated into the main branch of CORECLR (see Merge Pull Request #117 from Kangaroo/osx), and the direct git checkout will compile. If the "not found for architecture x86_64" error occurs at compile time, you need to remove the binaries folder and recompile.

After compiling successfully, you will see the following three files in the Binaries/product/amd64/debug folder:

Corerunlibcoreclr.dyliblibmscordaccore.dylib

Immediately after the success of the compilation of joy, an impulse arises--with this self-compiled CORECLR run. NET programs.

To run. NET program, it is found that Binaries/product/amd64/debug is missing an important file--mscorlib.dll, and I do not know why it was not generated at compile time.

@kangaroo also know this problem, send this file to me (if you need it, you can download it here), and then copy the file to Binaries/product/amd64/debug.

The next step is to prepare to run. NET program, suddenly thought of reading the garden before the post with CIL writing procedures: Hello, Wald, according to hand-knocked out a paragraph. NET console Application (code below), why not use this?

. assembly extern mscorlib{    . Ver 4:0:0:0    . PublicKeyToken = (B7 7A 5C) E0 '}.assembly ' {    . c ustom instance void class [Mscorlib]system.runtime.compilerservices.runtimecompatibilityattribute:: '. ctor ' () = ( In the 4E 6F 6E of each of the above        -the    ---------- HM 0x00008004    . Ver  0:0:0:0}.module HelloWorld.exe.method static void Main () {    . entrypoint    . maxstack 1    ldstr "Hello, world!"    call void [Mscorlib]system.console::writeline (String)        ret}

The IL code is then born into Assembly HelloWorld.exe with the ILAsm of Mono:

ILAsm helloworld.il

The HelloWorld.exe is then copied to the Binaries/product/amd64/debug, and now there are 5 files in this folder:

/git/dotnet/coreclr/binaries/product/amd64/ DebugHelloWorld.execorerunlibcoreclr.dyliblibmscordaccore.dylibmscorlib.dll

Exciting moments of tension come, let's try to run HelloWorld.exe with our own compiled CORECLR:

$./corerun Helloworld.exehello, world!

Yes! Success!

Although this is only a small step, while implementing a. NET application on a Mac is a long way off, the excitement of. NET open source has arrived!

Run the. NET program on Mac OS X with your own compiled CORECLR

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.