Microsoft MVP성태의 닷넷 이야기
.NET Framework: 506. .NETCore = CoreFX + CoreCLR [링크 복사], [링크+제목 복사]
조회: 19859
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 4개 있습니다.)

.NETCore = CoreFX + CoreCLR

".NET Core"가 공개되었습니다.

CoreCLR Now Open Source 
; http://www.i-programmer.info/news/89-net/8247-coreclr-now-open-source.html

쉽게 말해서 .NET Core는 우리가 알고 있는 ".NET Framework"의 소형 버전이라고 보시면 됩니다.

닷넷으로 만든 프로그램이 동작하려면 크게 2가지 구성요소가 있어야 하는데요. 바로 "JIT" 컴파일 등을 담당하는 런타임 환경이 그 하나이고, 또 다른 구성 요소는 우리가 프로그램을 만들 때 사용하는 여러 타입들이 정의된 "BCL(Base Class Library)"이 그것입니다.

따라서, .NET Core, CoreFX, CoreCLR을 기존의 ".NET Framework"과 비교하면 이렇게 됩니다.

.NET Core      = CoreFX + CoreCLR
.NET Framework = BCL    + CLR

그리고, CoreFX, CoreCLR의 소스 코드가 모두 github에 올라가 진행 중입니다.

dotnet/coreclr 
; https://github.com/dotnet/coreclr

dotnet/corefx 
; https://github.com/dotnet/corefx

게다가 https://github.com/dotnet/coreclr 글의 내용이 흥미진진합니다.

CoreCLR is a subset of the .NET Framework CLR. They share the same codebase and are updated together. For example, an update to the .NET GC improves both CoreCLR and the .NET Framework CLR.


CoreCLR이 .NET Framework CLR과 동일한 코드 기반이기 때문에, 이제는 .NET Framework CLR 측에서 문제가 발생했을 때 추측만이 아니라 검증도 해볼 수 있게 된 것입니다.

마이크로소프트 측은 기존 Mono에서 동작 중인 ASP.NET 5도 CoreCLR이 Linux/Mac용으로 포팅되는 시점에는 CoreCLR로 이전하겠다는 발표도 하고 있습니다.

CoreCLR is now Open Source
; https://devblogs.microsoft.com/dotnet/coreclr-is-now-open-source/

We’ve been talking about ASP.NET 5 for nearly a year now. You can build ASP.NET 5 apps with the .NET Framework or with .NET Core. Today, ASP.NET 5 uses the Mono runtime to run on Linux and Mac. Once .NET Core supports Linux and Mac, then ASP.NET 5 will move to using .NET Core for those platforms.


이렇게 되면 Mono의 향방이 궁금해집니다. 개인적인 의견으로는, Mono가 없어진다기 보다는 CoreCLR의 일정 부분을 흡수하지 않겠는가... 하는 생각을 해봅니다. 혹시 Mono가 CoreCLR 코드 베이스를 완전하게 흡수하는 것은 어떨까요? 글쎄요!!! 그렇다면 하위 호환성을 아예 포기해야 할 것입니다. 가령, Mono Profiler의 규격은 자체 확장한 것이기 때문에 CoreCLR의 Profiler 규격과는 맞지 않습니다. 그런 부분의 호환을 포기한다면 Mono가 CoreCLR을 흡수해 대대적인 성능 향상을 기대해 볼 수도 있을 것입니다. (사실... 저 쪽 동네는 하위 호환을 그다지 중요하지 않게 생각하는 분위기가 있으므로.)




그럼, 어디 ^^ 윈도우 용으로 빌드를 해볼까요?

Developer Guide - Building the repository
; https://github.com/dotnet/coreclr/wiki/Developer-Guide

우선, coreclr-master.zip를 다운로드 받아 압축을 해제합니다. 제 경우에는 e:\coreclr로 했습니다.

그다음 cmake를 다운로드 받습니다.

cmake-3.1.3-win32-x86.zip
; http://www.cmake.org/files/v3.1/cmake-3.1.3-win32-x86.zip

제 경우에는 e:\cmake에 압축을 해제했습니다.

이제 cmd.exe 창을 열고 다음과 같이 SET 명령을 수행해 cmake 폴더를 포함시켜둡니다. (또는 전역 환경 변수에 포함해둡니다.)

SET PATH=%PATH%;e:\cmake\bin

그리고, Visual Studio도 설치되어 있어야 합니다. 없다면 무료 버전인 Visual Studio Community를 다운로드 받아 설치합니다.

Visual Studio Community
; https://app.vssps.visualstudio.com/profile/review?download=true&family=VisualStudio&edition=Community&release=VisualStudio2013Upd4

설치 후, "DIA SDK"가 있는지 아래의 경로에서 확인합니다.

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\DIA SDK"

없으면, 이 글의 마지막에 있는 DIA SDK 관련 설명을 참조하세요.

이걸로 사전 설치 준비 작업은 끝!

(** 2016-08-23 업데이트: 빌드를 위해 Python이 추가되었습니다. 자세한 사항은 Build CoreCLR on Windows 글을 참고하세요.)




자, 이제 명령행에서 루트에 있는 build.cmd 파일을 실행해 빌드해 줍니다.

E:\coreclr>build.cmd
Commencing CoreCLR Repo build

Checking pre-requisites...

Commencing build of native components for Windows_NT.x64.debug

-- The C compiler identification is MSVC 18.0.31101.0
-- The CXX compiler identification is MSVC 18.0.31101.0
-- Check for working C compiler using: Visual Studio 12 2013 Win64
-- Check for working C compiler using: Visual Studio 12 2013 Win64 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 12 2013 Win64
-- Check for working CXX compiler using: Visual Studio 12 2013 Win64 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- The ASM_MASM compiler identification is MSVC
-- Found assembler: c:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/x86_amd64/ml64.exe
-- Configuring done
-- Generating done
-- Build files have been written to: E:/coreclr/binaries/intermediates/Windows_NT.x64.debug
Build started 2015-03-04 10:22:07.

...[생략]...

빌드 하다가 "error CS0518: Predefined type 'System.Object' is not defined or imported" 오류가 발생할 수 있는데 일단 이것은 무시합니다. 그 오류 메시지가 나타날때까지 빌드가 진행되었으면 이미 필요한 DLL들은 다음의 폴더에 생성된 이후입니다. (예를 들어, coreclr.dll, mscorlib.dll, sos.dll, ...)

E:\coreclr\binaries\Product\Windows_NT.x64.debug

이렇게 build.cmd로 빌드를 한번 해주면 "E:\coreclr\binaries\intermediates\Windows_NT.x64.debug\CoreCLR.sln" 파일이 생성됩니다. 이후부터는, 이것을 Visual Studio에 로드해서 컴파일하고 디버깅할 수 있습니다. 물론, "F5 디버깅"도 가능하겠지요? ^^ 방법은 이전에 설명했던 글과 유사하게 진행하시면 됩니다.

OpenCover 소스 코드 분석을 Visual Studio 2013에서 하는 방법
; https://www.sysnet.pe.kr/2/0/2883




그럼, 이제 (Microsoft .NET Framework 런타임이 아닌) "E:\coreclr\binaries\Product\Windows_NT.x64.debug" 폴더에 있는 CoreCLR 런타임으로 간단한 응용 프로그램 하나 실행해 볼까요? ^^

Visual Studio를 이용해 아래와 같은 콘솔 프로젝트를 하나 만들어 빌드하고,

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Main");
            Console.ReadLine();
        }
    }
}

"E:\coreclr\binaries\Product\Windows_NT.x64.debug" 폴더의 corerun.exe를 이용해 다음과 같이 실행해 볼 수 있습니다.

E:\coreclr\binaries\Product\Windows_NT.x64.debug>corerun .\samples\ConsoleApplication1.exe
Main

Console.ReadLine 코드는 일부러 집어 넣은 것입니다. 그 코드로 인해 실행 중에 대기를 하면, 그 시점에 Process Explorer를 이용해 재미있는 결과를 확인할 수 있습니다. 즉, ConsoleApplication1.exe 파일이 CoreRun.exe의 자식이 아닌 CoreRun.exe 자체 내에서 DLL처럼 로드되어 Main 함수가 실행된 것을 확인할 수 있습니다.

corerun_1.png

그러니까, java.exe가 .class파일을 실행하는 것처럼, coreclr에서는 exe파일은 단지 "Main 메서드를 포함하고 있는 dll"이라는 의미에 불과합니다.

물론, 윈도우 환경에서는 ConsoleApplication1.exe 파일을 직접 실행할 수 있고 그런 경우에는 .NET Framework의 영향을 받게 됩니다. (나중에 CoreCLR이 Max/Linux 환경에 포팅이 되면, 방금 전에 만들어 둔 ConsoleApplication1.exe 파일만 다른 환경의 CoreCLR 폴더에 복사해 동일하게 corerun을 이용해 실행해 볼 수 있습니다.)




예전에 아래와 같은 주제로 이야기한 적이 있었지요?

.NET EXE 파일을 닷넷 프레임워크 버전에 상관없이 실행할 수 있을까요? - 두 번째 이야기
; https://www.sysnet.pe.kr/2/0/1746

이젠, corerun.exe 파일과 함께 몇몇 필요한 파일을 함께 배포해 주면 더 이상 .NET Framework 버전에 의존하지 않는 응용 프로그램을 제작할 수 있습니다.

단지, 크로스-플랫폼적인 것이 고려되었기 때문에 아직 WinForm/WPF/WCF와 같은 라이브러리들은 CoreFX에서 지원되지 않아 사용할 수 없습니다. (지원 여부가 불투명 합니다. 아마... 이런 부분은 지원한다고 해도 시간이 제법 걸릴 것입니다.) 현재로써는 ASP.NET 5나 콘솔 응용 프로그램 정도를 개발할 때 쓸 수 있습니다. 아쉽지만! ^^

참고로 맥 운영체제인 OSX에서도 coreclr을 빌드하는 글이 있습니다.

Building and Running .NET’s CoreCLR on OS X
; http://praeclarum.org/post/110552954728/building-and-running-nets-coreclr-on-os-x

점점 더 영역을 확장할 테니 기대해도 좋을 듯 합니다. ^^




지금부터는 빌드 시 겪을 수 있는 오류 상황에 대한 설명입니다.

만약 DIA SDK가 정상적으로 설치되지 않았다면 다음과 같은 오류가 발생합니다.

E:\coreclr>build.cmd Commencing CoreCLR Repo build

Checking pre-requisites...

Commencing build of native components for Windows_NT.x64.debug

Error: DIA SDK is missing at "C:\Program Files (x86)\Microsoft Visual Studio 12.0\DIA SDK". This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "C:\Program Files (x86)\Microsoft Visual Studio 12.0\" but rather at VS install location of previous version. Workaround is to copy DIA SDK fold
er from VS install location of previous version to "C:\Program Files (x86)\Microsoft Visual Studio 12.0\" and then resume build.
Visual Studio 2013 Express does not include the DIA SDK. You need Visual Studio 2013 Community (free).
See: https://github.com/dotnet/coreclr/wiki/Developer-Guide#prerequisites


오류 메시지에 의하면, Visual Studio 2013을 설치할 때 이전 버전의 Visual Studio가 설치되어 있으면 그쪽 폴더에 설치된다고 합니다. 예를 들어, 제 경우에는 컴퓨터에 Visual Studio 2012가 설치되어 있었는데 그래서 다음의 경로에 DIA SDK가 설치되어 있었습니다.

C:\Program Files (x86)\Microsoft Visual Studio 11.0\DIA SDK

따라서 다음의 명령을 관리자 권한으로 실행한 cmd.exe 창에서 실행해 주면 됩니다.

robocopy "C:\Program Files (x86)\Microsoft Visual Studio 11.0\DIA SDK" "C:\Program Files (x86)\Microsoft Visual Studio 12.0\DIA SDK" /S

또 다른 상황으로, 만약 cmake가 정상적으로 PATH에 연결되어 있지 않으면 다음과 같은 오류가 발생합니다.

E:\coreclr>build.cmd Commencing CoreCLR Repo build

Checking pre-requisites...

CMake is a pre-requisite to build this repository but it was not found on the path. Please install CMake from http://www.cmake.org/download/ and ensure it is on your path.


당연히 cmake를 다운로드/압축 풀고 PATH 환경 변수에 경로를 설정해 주면 문제가 해결됩니다.

마지막으로, 본문에서 다뤘던 "CSC : error CS0518: Predefined type 'System.Object' is not defined or imported" 오류가 빌드를 완료하지 못하고 나타나는 문제입니다.

Commencing build of tests for Windows_NT.x64.debug

Doing a clean test build

Starting the Test Build

  Restoring build tools...
  Restoring all package dependencies...
E:\coreclr\tests\src\packages\Microsoft.DotNet.BuildTools.1.0.21-prerelease\lib\packageresolve.targets(25,5): warning : Unable to resolve the assets of System.Diagnostics.Process: Couldn't find a matching group [E:\coreclr\tests\src\Common\Coreclr.TestWrapper\Coreclr.TestWrapper.csproj]
E:\coreclr\tests\src\packages\Microsoft.DotNet.BuildTools.1.0.21-prerelease\lib
...[생략]....

E:\coreclr\tests\src\packages\Microsoft.DotNet.BuildTools.1.0.21-prerelease\lib\packageresolve.targets(25,5): warning : Unable to resolve the assets of System.Reflection.Primitives: Couldn't find a matching group [E:\coreclr\tests\src\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj]
CSC : error CS0518: Predefined type 'System.Object' is not defined or imported
[E:\coreclr\tests\src\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj]

...[생략]....

최초 발생하는 오류는 System.Object를 찾을 수 없다는 것입니다.

CSC : error CS0518: Predefined type 'System.Object' is not defined or imported [E:\coreclr\tests\src\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj]

왜냐하면 해당 csproj 프로젝트 빌드가 nostdlib 옵션으로 컴파일되기 때문인데 구체적인 해결 방법은 다음에 더 알아보도록 하겠습니다. 지금은 일단, 이 빌드 오류가 발생해도 CoreCLR 빌드는 정상적으로 되었으므로 무시해도 좋습니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 4/23/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2015-03-13 04시05분
[ryujh] 안녕하세요.

본문 중에

.NET Core = CoreFX + CoreCLR
.NET Framework = BCL + CLR

이런 관계인데 .NET Framework Client Profile 과 위의 것의 관계는 어떤지 문의합니다.

본문 아래의 실행법은 java의 영향을 받은 것인가요?


저는 아직도 vs2008을 사용하고 있는데(가끔 vs2012 사용) 이제 버전업을 해야할 것 같습니다.

감사합니다.
[guest]
2015-03-13 04시28분
.NET Framework Client Profile은 위의 관계에 낄 수는 없습니다. ^^ .NET 런타임이 40MB 넘게 무거워지니까, 서버 쪽 구성요소같은 클라이언트 응용 프로그램 제작에 잘 쓰이지 않는 구성 요소를 제거해서 만든 .NET 런타임이 "Client Profile"입니다. (ClickOnce 응용 프로그램 배포를 빠르게 하기 위해 만들어진 듯 하지만... 실상은 얼마 차이기 나지 않기 때문에 혹시 모를 타입 사용을 위해 Full Framework 버전을 보통 사용하게 됩니다.)

java의 영향을 받았다기 보다는, 운영체제에 의해 직접 해석되는 실행 모듈이 아니기 때문에 저렇게 다른 프로세스에 실려서 실행할 수 밖에 없습니다.
정성태
2016-08-23 02시43분
copy bin\Product\Windows_NT.x64.debug\clrjit.dll ..\coreclr-demo\runtime
copy bin\Product\Windows_NT.x64.debug\CoreRun.exe ..\coreclr-demo\runtime
copy bin\Product\Windows_NT.x64.debug\coreclr.dll ..\coreclr-demo\runtime
copy bin\Product\Windows_NT.x64.debug\mscorlib.dll ..\coreclr-demo\runtime
copy bin\Product\Windows_NT.x64.debug\System.Private.CoreLib.dll ..\coreclr-demo\runtime
정성태
2016-08-23 02시49분
copy bin\Windows_NT.AnyCPU.Debug\System.Console\System.Console.dll ..\coreclr-demo\runtime
copy bin\Windows_NT.AnyCPU.Debug\System.Diagnostics.Debug\System.Diagnostics.Debug.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.IO\System.IO.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.IO.FileSystem.Primitives\System.IO.FileSystem.Primitives.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.Runtime\System.Runtime.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.Runtime.InteropServices\System.Runtime.InteropServices.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.Text.Encoding\System.Text.Encoding.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.Text.Encoding.Extensions\System.Text.Encoding.Extensions.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.Threading\System.Threading.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.Threading.Tasks\System.Threading.Tasks.dll ..\coreclr-demo\runtime
정성태
2017-01-31 01시00분
정성태

[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13600정성태4/18/2024249닷넷: 2242. C# - 관리 스레드와 비관리 스레드
13599정성태4/17/2024271닷넷: 2241. C# - WAV 파일의 PCM 사운드 재생(Windows Multimedia)파일 다운로드1
13598정성태4/16/2024284닷넷: 2240. C# - WAV 파일 포맷 + LIST 헤더파일 다운로드1
13597정성태4/15/2024360닷넷: 2239. C# - WAV 파일의 PCM 데이터 생성 및 출력파일 다운로드1
13596정성태4/14/2024709닷넷: 2238. C# - WAV 기본 파일 포맷파일 다운로드1
13595정성태4/13/2024832닷넷: 2237. C# - Audio 장치 열기 (Windows Multimedia, NAudio)파일 다운로드1
13594정성태4/12/2024999닷넷: 2236. C# - Audio 장치 열람 (Windows Multimedia, NAudio)파일 다운로드1
13593정성태4/8/20241049닷넷: 2235. MSBuild - AccelerateBuildsInVisualStudio 옵션
13592정성태4/2/20241202C/C++: 165. CLion으로 만든 Rust Win32 DLL을 C#과 연동
13591정성태4/2/20241164닷넷: 2234. C# - WPF 응용 프로그램에 Blazor App 통합파일 다운로드1
13590정성태3/31/20241071Linux: 70. Python - uwsgi 응용 프로그램이 k8s 환경에서 OOM 발생하는 문제
13589정성태3/29/20241140닷넷: 2233. C# - 프로세스 CPU 사용량을 나타내는 성능 카운터와 Win32 API파일 다운로드1
13588정성태3/28/20241191닷넷: 2232. C# - Unity + 닷넷 App(WinForms/WPF) 간의 Named Pipe 통신파일 다운로드1
13587정성태3/27/20241149오류 유형: 900. Windows Update 오류 - 8024402C, 80070643
13586정성태3/27/20241293Windows: 263. Windows - 복구 파티션(Recovery Partition) 용량을 늘리는 방법
13585정성태3/26/20241094Windows: 262. PerformanceCounter의 InstanceName에 pid를 추가한 "Process V2"
13584정성태3/26/20241046개발 환경 구성: 708. Unity3D - C# Windows Forms / WPF Application에 통합하는 방법파일 다운로드1
13583정성태3/25/20241149Windows: 261. CPU Utilization이 100% 넘는 경우를 성능 카운터로 확인하는 방법
13582정성태3/19/20241406Windows: 260. CPU 사용률을 나타내는 2가지 수치 - 사용량(Usage)과 활용률(Utilization)파일 다운로드1
13581정성태3/18/20241585개발 환경 구성: 707. 빌드한 Unity3D 프로그램을 C++ Windows Application에 통합하는 방법
13580정성태3/15/20241136닷넷: 2231. C# - ReceiveTimeout, SendTimeout이 적용되지 않는 Socket await 비동기 호출파일 다운로드1
13579정성태3/13/20241493오류 유형: 899. HTTP Error 500.32 - ANCM Failed to Load dll
13578정성태3/11/20241628닷넷: 2230. C# - 덮어쓰기 가능한 환형 큐 (Circular queue)파일 다운로드1
13577정성태3/9/20241870닷넷: 2229. C# - 닷넷을 위한 난독화 도구 소개 (예: ConfuserEx)
13576정성태3/8/20241543닷넷: 2228. .NET Profiler - IMetaDataEmit2::DefineMethodSpec 사용법
[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...