Win10上編譯CoreCLR的Windows和Linux版本


一、編譯環境

首先,不管是Windows還是Linux版本CoreCLR的編譯,都是在Windows10上進行的。

二、CoreCLR for Windows

在Windows上做編譯怎么能少得了Visual Studio,由於Visual Studio 2017剛剛發布,所以選用Visual Studio 2017版本作為編譯工具。

編譯組件

Visual Studio 2017安裝組件

.NET Desktop Development

  • All Required Components
  • .NET Framework 4-4.6 Development Tools

Desktop Development with C++

  • All Required Components
  • VC++ 2017 v141 Toolset (x86, x64)
  • Windows 8.1 SDK and UCRT SDK
  • VC++ 2015.3 v140 Toolset (x86, x64)

還有一個比較重要的問題,就是使用VS2017的話,還需要注冊一個Visual Studio 2015的組件,需要運行如下命令:regsvr32.exe %VSINSTALLDIR%\Common7\IDE\msdia120.dll ,因為需要VS2017的環境變量,當然這也需要在Developer Command Prompt for VS2017 中運行。
還有最重要一點Visual Studio Express 2017不支持編譯CoreCLR。

CMake

要編譯CoreCLR需要CMake 3.7.2及以上版本,記得加環境變量Path。

Python

官方給出的所需版本為 python 2.7.9,但是python 3也能很好的支持,記得加環境變量Path。

Git

這個是必需的嘛。

PowerShell

Windows 10 自帶4.0,所以Win10就沒問題。

DotNet Core SDK

不需要解釋吧,沒有去官網下載吧。

windows編譯

其實這部分有個小插曲就是,如果使用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版本。

三、CoreCLR for Linux

這里使用Windows 10編譯Linux版本是因為Win10里帶有Bash,bash是一個基於Ubuntu 14.04的Windows子系統,可以“完美”模擬Linux環境,當然下面所講的過程也完全可以在真正的Ubuntu上編譯。

系統

官方推薦的是ubuntu 14.04,當然也可以是別的Linux版本,本文也是使用這個版本進行的。

系統組件

  • 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
  • git

要安裝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

Linux編譯

./build.sh

四、總結

Linux上的編譯相對比較簡單,但是如果是DEBUG的話,Windows版本要很容易實現。編譯兩個版本的過程中會經過漫長的等待(最好找個代理)。

下篇文章我會講下在Windows環境下的調試,還有我做的一些小的修改過程。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM