码迷,mamicode.com
首页 > Windows程序 > 详细

Windows下编译运行CoreCLR

时间:2015-03-15 13:51:29      阅读:1163      评论:0      收藏:0      [点我收藏+]

标签:

之前一直运行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

标签:

原文地址:http://www.cnblogs.com/bartmao/p/4338826.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!