首先,不管是Windows还是Linux版本CoreCLR的编译,都是在Windows10上进行的。
在Windows上做编译怎么能少得了Visual Studio,由于Visual Studio 2017刚刚发布,所以选用Visual Studio 2017版本作为编译工具。
.NET Desktop Development
Desktop Development with C++
还有一个比较重要的问题,就是使用VS2017的话,还需要注册一个Visual Studio 2015的组件,需要运行如下命令:regsvr32.exe %VSINSTALLDIR%\Common7\IDE\msdia120.dll ,因为需要VS2017的环境变量,当然这也需要在Developer Command Prompt for VS2017 中运行。 还有最重要一点Visual Studio Express 2017不支持编译CoreCLR。
要编译CoreCLR需要CMake 3.7.2及以上版本,记得加环境变量Path。
官方给出的所需版本为 python 2.7.9,但是python 3也能很好的支持,记得加环境变量Path。
这个是必需的嘛。
Windows 10 自带4.0,所以Win10就没问题。
不需要解释吧,没有去官网下载吧。
其实这部分有个小插曲就是,如果使用Visual Studio 2017编译的话会有一个小BUG,文档上给的例子是直接运行命令:
./build.cmd
但是会得到如下结果:
Microsoft.CSharp.Core.targets(106,11): error MSB4064: The "OverrideToolHost" parameter is not supported by the "Csc" task. Verify the parameter exists on the task, and it is a settable public instance property.
BUG的地址如下:https://github.com/dotnet/coreclr/issues/10056
运行下面三条命令其中之一就可以解决这个问题了,解决方法如下:
build x64 skiptests -- /p:CSharpCoreTargetsPath=Roslyn\Microsoft.CSharp.Core.targets
build x64 checked skiptests -- /p:CSharpCoreTargetsPath=Roslyn\Microsoft.CSharp.Core.targets
build x64 release skiptests -- /p:CSharpCoreTargetsPath=Roslyn\Microsoft.CSharp.Core.targets
推荐第一条命令,生成DEBUG版本。
这里使用Windows 10编译Linux版本是因为Win10里带有Bash,bash是一个基于Ubuntu 14.04的Windows子系统,可以“完美”模拟Linux环境,当然下面所讲的过程也完全可以在真正的Ubuntu上编译。
官方推荐的是ubuntu 14.04,当然也可以是别的Linux版本,本文也是使用这个版本进行的。
要安装lldb-3.6需要在Ubuntu上添加安装源:
echo "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.6 main" | sudo tee /etc/apt/sources.list.d/llvm.list
wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
如果系统里没有git的话,需要自己安装下。接着要安装组件,命令如下:
sudo apt-get install cmake llvm-3.5 clang-3.5 lldb-3.6 lldb-3.6-dev libunwind8 libunwind8-dev gettext libicu-dev liblttng-ust-dev libcurl4-openssl-dev libssl-dev uuid-dev
./build.sh
Linux上的编译相对比较简单,但是如果是DEBUG的话,Windows版本要很容易实现。编译两个版本的过程中会经过漫长的等待(最好找个代理)。
下篇文章我会讲下在Windows环境下的调试,还有我做的一些小的修改过程。