Windows下編譯運行CoreCLR

來源:互聯網
上載者:User

標籤:

之前一直運行Corefxlab的HelloWorld失敗,於是用隨筆記錄下自己的操作過程。

作業系統:Win8 Pro x64, 處理器AMD A8-3870。已安裝VisualStudio 2013 Utimate,VisualStudio 2015 Preview。

參考文檔: https://github.com/dotnet/coreclr/wiki/Developer-Guide

步驟

1. 下載cmake-3.2.0-rc2-win32-x86,安裝。

2. 拉取CoreCLR最新版本。

3. 開啟Developer Comand Prompt for 2014, 切換到Git/coreclr目錄,type [build clean]

這次跟我在公司編譯結果不一樣。這次代碼編譯成功,Test編譯失敗。

錯誤記錄檔為

“D:\Git\coreclr\tests\build.proj”(rebuild 目標) (1) ->
“D:\Git\coreclr\tests\src\dirs.proj”(Build 目標) (2) ->
“D:\Git\coreclr\tests\src\Regressions\assemblyref\assem.csproj”(Build 目標) (23) ->
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\AppxPackage\Microsoft.AppXPackage.Targets(451,9): error APPX1639: 未找到檔案“Windows.props”。 有關詳細資料,請參閱 http://go.microsoft.com/fwlink/?prd=12395&pver=1.0&plcid=0x409&ar=MSDN&sar=PlatformMultiTargeting&o1=C:\Program Files (x86)\Microsoft SDKs\Portable\v12.0&o2=Portable。 [D:\Git\coreclr\tests\src\Regressions\assemblyref\assem.csproj]

 但是這次編譯出來的dll似乎正常了。用Dependency查看coreclr.dll。所有依賴的dll都是x64的。僅缺少一個IESHIMS.DLL,從Windows目錄下搜尋到,複製到目前的目錄。

Dependency還報一個Warning:

Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

4.  嘗試運行一把。Cmd下type [CoreRun test]

HOSTLOG: Host directory: D:\Git\coreclr\binaries\Product\Windows_NT.x64.debug\
HOSTLOG: CORE_ROOT not set; skipping
HOSTLOG: You can set the environment variable CORE_ROOT to point to the path
HOSTLOG: where CoreCLR.dll lives to help CoreRun.exe find it.
HOSTLOG: Attempting to load: D:\Git\coreclr\binaries\Product\Windows_NT.x64.deb
ug\CoreCLR.dll
HOSTLOG: Loaded: D:\Git\coreclr\binaries\Product\Windows_NT.x64.debug\CoreCLR.d
ll
HOSTLOG: Loading: D:\Git\coreclr\binaries\Product\Windows_NT.x64.debug\text
HOSTLOG: Finding GetCLRRuntimeHost(...)
HOSTLOG: Calling GetCLRRuntimeHost(...)
HOSTLOG: Setting ICLRRuntimeHost2 startup flags
HOSTLOG: Starting ICLRRuntimeHost2
HOSTLOG: CORE_LIBRARIES not set; skipping
HOSTLOG: You can set the environment variable CORE_LIBRARIES to point to a
HOSTLOG: path containing additional platform assemblies,
HOSTLOG: Adding assemblies from D:\Git\coreclr\binaries\Product\Windows_NT.x64.
debug\ to the TPA list
HOSTLOG: Creating an AppDomain
HOSTLOG: TRUSTED_PLATFORM_ASSEMBLIES=D:\Git\coreclr\binaries\Product\Windows_NT
.x64.debug\clretwrc.dll;D:\Git\coreclr\binaries\Product\Windows_NT.x64.debug\cor
eclr.dll;D:\Git\coreclr\binaries\Product\Windows_NT.x64.debug\dbgshim.dll;D:\Git
\coreclr\binaries\Product\Windows_NT.x64.debug\ieshims.dll;D:\Git\coreclr\binari
es\Product\Windows_NT.x64.debug\mscordaccore.dll;D:\Git\coreclr\binaries\Product
\Windows_NT.x64.debug\mscordbi.dll;D:\Git\coreclr\binaries\Product\Windows_NT.x6
4.debug\mscorlib.dll;D:\Git\coreclr\binaries\Product\Windows_NT.x64.debug\mscorr
c.debug.dll;D:\Git\coreclr\binaries\Product\Windows_NT.x64.debug\mscorrc.dll;D:\
Git\coreclr\binaries\Product\Windows_NT.x64.debug\sos.dll;D:\Git\coreclr\binarie
s\Product\Windows_NT.x64.debug\coreconsole.exe;D:\Git\coreclr\binaries\Product\W
indows_NT.x64.debug\corerun.exe;
HOSTLOG: APP_PATHS=D:\Git\coreclr\binaries\Product\Windows_NT.x64.debug\
HOSTLOG: APP_NI_PATHS=D:\Git\coreclr\binaries\Product\Windows_NT.x64.debug\NI;D
:\Git\coreclr\binaries\Product\Windows_NT.x64.debug\
HOSTLOG: NATIVE_DLL_SEARCH_DIRECTORIES=D:\Git\coreclr\binaries\Product\Windows_
NT.x64.debug\;D:\Git\coreclr\binaries\Product\Windows_NT.x64.debug\
HOSTLOG: AppDomainCompatSwitch=UseLatestBehaviorWhenTFMNotSpecified
HOSTLOG: APP_LOCAL_WINMETADATA=

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass
embly ‘text‘ or one of its dependencies. 系統找不到指定的檔案。

 看起來運行時是跑起來了,這跟我上次編譯結果不一樣啊。難道之前是我公司機器的環境有問題?

5. 嘗試跑corefxlab下的HelloWorld

https://github.com/dotnet/corefxlab

主目錄下type [build]

然後分別編譯NuGetTasks和HelloWorld。
運行產生的HelloWorld.exe,提示

無法啟動此程式,因為電腦中丟失api-ms-win-core-localization-obsolete-|1-2-0.dll。嘗試重新安裝該程式以解決問題。

只好再編譯corefx

https://github.com/dotnet/corefx/wiki/Developer-Guide

取出產生的package檔案夾下的api-ms-win-core-localization-obsolete-|1-2-0.dll到HelloWorld目錄下。再運行,還是缺dll。幾番嘗試,

共copy如下dll

api-ms-win-core-kernel32-legacy-l1-1-1.dll

api-ms-win-core-localization-l1-2-1.dll

api-ms-win-core-localization-obsolete-l1-2-0.dll

api-ms-win-core-stringloader-l1-1-1.dll

最終運行成功。

看來在公司運行失敗確實和環境有關係吧。

6. 嘗試用編譯的CoreRun運行HelloWorld

試了兩種方式:

1) 把編譯出來的HelloWorld整個檔案夾拷到CoreCLR編譯出來的檔案夾下。type[corerun HelloWorld\HelloWor

ld.exe],報錯,原因未知。

Unhandled Exception: System.BadImageFormatException: Could not load file or asse
mbly ‘HelloWorld.exe‘ or one of its dependencies. The module was expected to con
tain an assembly manifest.

2)按照http://blogs.msdn.com/b/dotnet/archive/2015/02/03/coreclr-is-now-open-source.aspx?Redirected=true&PageIndex=2做法:

Modify CoreCLR to your heart’s content

Build CoreCLR via build.cmd x64 release

Copy the following files from coreclr\binaries\x64\release to corfxlab\demos\CoreClrConsoleApplications\HelloWorld\NotYetPackages\CoreCLR:coreclr.dll,CoreConsole.exe,mscorlib.dll

Rebuild HelloWorld.sln (either using the command line or in VS)

我也不知道意義何在,試了一把果然沒效果。

 

總結:

還有幾個問題要搞清楚:
1. 如何使HelloWorld.exe運行在自己編譯出來的CoreCLR上。

2. 解決幾個Test運行失敗的原因。

3. 編譯CoreCLR缺失的IESHIMS.DLL, 和編譯HelloWorld缺失的“api-”打頭的dll既然是必須的,為什麼不直接在packages裡提供?

 

Windows下編譯運行CoreCLR

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.