Microsoft MVP성태의 닷넷 이야기
.NET Framework: 778. (Unity가 사용하는) 모노 런타임의 __makeref 오류 [링크 복사], [링크+제목 복사]
조회: 12441
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 3개 있습니다.)

(Unity가 사용하는) 모노 런타임의 __makeref 오류

아래의 글에 달린 덧글 덕분에,

C#에서 enum을 boxing 없이 int로 변환하기 - 두 번째 이야기
; https://www.sysnet.pe.kr/2/0/11506

실로 오랜만에 Mono 런타임을 설치해봤습니다. ^^

The latest Stable Mono
; https://www.mono-project.com/download/stable/

설치하고 나면 시작 메뉴에 "Open Mono x64 Command Prompt" 항목이 생깁니다. 그 명령행 창을 열고 다음의 소스 코드를,

using System;

namespace ConsoleApp1
{
    class Program
    {
        enum EnumState
        {
            A,
            B,
        }

        static void Main(string[] args)
        {
            unsafe
            {
                EnumState a = EnumState.A;
                EnumState b = EnumState.B;

                TypedReference refA = __makeref(a);
                TypedReference refB = __makeref(b);

                int* valuePtrA = (int*)*((IntPtr*)&refA);
                int* valuePtrB = (int*)*((IntPtr*)&refB);

                int expectedA = *valuePtrA;
                int expectedB = *valuePtrB;

                Console.WriteLine(expectedA);
                Console.WriteLine(expectedB);
                Console.WriteLine(expectedA == expectedB);
            }

            Console.ReadLine();
        }
    }
}

이렇게 빌드할 수 있습니다.

C:\temp>dmcs Program.cs /unsafe

실행해 보면, 결과가 잘 나옵니다.

C:\temp>Program.exe
0
1
False

오호~~~ 그런데 원하는 환경이 아닙니다. 저렇게 실행하면 ^^ 현재 윈도우에 설치된 .NET Full Framework가 올라오게 됩니다. 따라서 모노 런타임 위에서 실행하려면 다음과 같이 mono.exe를 이용해 실행해야 합니다.

c:\temp>mono Program.exe
898445256
898445256
True

출력된 898445256 값은 실행 시마다 달라지는 것으로 봐서 메모리 상의 쓰레기 값이 출력되는 듯합니다. 결과적으로, 모노 런타임은 __makeref 예약어에 대한 처리를 제대로 하지 못하는 것입니다.




그래도, Unity의 경우 AOT(Ahead of time) 컴파일러를 사용해 미리 빌드해 놓기 때문에 혹시 거기서는 정상적으로 처리하고 있지 않을까요? ^^ AOT 실행 테스트를 하려면 clang이 필요합니다. 이를 위해 LLVM을 설치해도 되지만,

LLVM Download Page 
; https://releases.llvm.org/download.html

Pre-Built Binaries:
Clang for Windows (64-bit) (.sig)
; http://releases.llvm.org/6.0.0/LLVM-6.0.0-win64.exe

어차피 clang.exe도 빌드할 때는 Visual C++의 cl.exe의 도움을 얻어야 하므로 Visual Studio를 설치해야 합니다.

Setting up Clang on Windows
; https://github.com/boostorg/hana/wiki/Setting-up-Clang-on-Windows

따라서, 그냥 Clang/LLVM을 설치하지 말고 Visual Studio에 포함된 clang 구성으로 옵션을 추가해 설치하면 됩니다. 가령 Visual Studio 2015의 경우 다음과 같은 옵션만 있으면 됩니다.

Visual Studio Professional 2015 with Update 3

Programming Languages
    - Visual C++
        - Common Tools for Visual C++ 2015
        - Microsoft Foundation Classes for C++
        - Windows XP Support for C++

Cross Platform Mobile Development
    - Visual C++ Mobile Development
        - Clang with Microsoft CodeGen (July 2016)

설치 후, 환경 변수에 PATH를 clang.exe와 link.exe에 대해 각각 다음과 같이 잡아줍니다.

[clang.exe의 위치를 PATH에 추가]
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ClangC2\bin\amd64

[link.exe의 위치를 PATH에 추가]
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64

이후, Program.exe 바이너리를 AOT 빌드해 줘야 합니다.

mono --aot=full Program.exe

그런 다음 아래와 같이 실행할 수 있는데, 아쉽게도 오류가 발생합니다.

C:\temp>mono --full-aot Program.exe
Failed to load AOT module 'C:\Program Files\Mono\lib\mono\4.5\mscorlib.dll.dll' in aot-only mode.

왜냐하면, Program.exe가 의존하는 모듈들도 전부 AOT 상태로 빌드가 되어있어야 하기 때문입니다. 이를 위해 다음의 경로에 있는 DLL들을 전부,

C:\Program Files\Mono\lib\mono\4.5\mscorlib.dll
C:\Program Files\Mono\lib\mono\gac\I18N\4.0.0.0__0738eb9f132ed756\I18N.dll
C:\Program Files\Mono\lib\mono\gac\I18N.West\4.0.0.0__0738eb9f132ed756\I18N.West.dll

개별 폴더에 들어가 각각 다음의 명령어로 빌드해 둡니다.

mono --aot=full mscorlib.dll
mono --aot=full I18N.dll
mono --aot=full i18n.west.dll

이후 다시 실행하면 다음과 같이 결과를 볼 수 있습니다. ^^

c:\temp>mono --full-aot Program.exe
-402205784
-402205784
True

뭐... 어쩔 수 없군요. ^^ Mono 런타임은, AOT 빌드한 결과물에서도 역시 __makeref 처리를 하지 못합니다.




Mono가 저렇다는 것은, 그에 기반을 둔 현재의 Unity가 게임 빌드 결과물에서 __makeref 처리를 못한다는 것을 의미합니다. 아마도 가장 좋은 것은 .NET Core로 Unity가 이전하는 것일 텐데 가장 최근의 결과물인 2018 버전의,

Updated scripting runtime in Unity 2018.1: What does the future hold?
; https://blogs.unity3d.com/kr/2018/03/28/updated-scripting-runtime-in-unity-2018-1-what-does-the-future-hold/

질문 답변을 봐도 희망이 안 보이는 것 같습니다. ^^

Q: Is .net core on the radar for the future at all? A: It is not something we’re looking at for the near future, for a few reasons. First, it does not have a full embedding API, as Mono does. Second, it does not support enough platforms currently. We have done some experiments with it though, so I can’t rule it out entirely. But we’re focused on other priorities at the moment, like build size, iteration time improvement, GC, and C#7.





참고로, clang.exe가 설치되지 않았거나 link.exe와 함께 PATH가 정상적으로 잡혀 있지 않으면 다음과 같은 식의 컴파일 오류가 발생합니다.

C:\temp>mono --aot Program.exe
Mono Ahead of Time compiler - compiling assembly C:\temp\Program.exe
AOTID B742BABC-9819-CB33-8E48-FF192EC74425
Code: 276(29%) Info: 6(0%) Ex Info: 47(4%) Unwind Info: 41(4%) Class Info: 129(13%) PLT: 30(3%) GOT Info: 301(31%) Offsets: 121(12%) GOT: 240
Compiled: 2/2 (100%), No GOT slots: 1 (50%), Direct calls: 0 (100%)
Executing the native assembler: "clang.exe" -c -x assembler  -o C:\Users\testuser\AppData\Local\Temp\mono_aot_a03412.obj C:\Users\testuser\AppData\Local\Temp\mono_aot_a03412
'"clang.exe"' is not recognized as an internal or external command,
operable program or batch file.
AOT of image Program.exe failed.




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/27/2018]

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

비밀번호

댓글 작성자
 




... 16  17  18  19  20  21  22  23  24  25  [26]  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
12971정성태2/15/20229677.NET Framework: 1157. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 muxing.c 예제 포팅 [7]파일 다운로드2
12970정성태2/15/20227818.NET Framework: 1156. C# - ffmpeg(FFmpeg.AutoGen): Bitmap으로부터 h264 형식의 파일로 쓰기 [1]파일 다운로드1
12969정성태2/14/20226450개발 환경 구성: 638. Visual Studio의 Connection Manager 기능(Remote SSH 관리)을 위한 명령행 도구 - 두 번째 이야기파일 다운로드1
12968정성태2/14/20226612오류 유형: 794. msbuild 에러 - error NETSDK1005: Assets file '...\project.assets.json' doesn't have a target for '...'.
12967정성태2/14/20226992VC++: 153. Visual C++ - C99 표준의 Compund Literals 빌드 방법 [4]
12966정성태2/13/20226857.NET Framework: 1155. C# - ffmpeg(FFmpeg.AutoGen): Bitmap으로부터 yuv420p + rawvideo 형식의 파일로 쓰기파일 다운로드1
12965정성태2/13/20226735.NET Framework: 1154. "Hanja Hangul Project v1.01 (파이썬)"의 C# 버전
12964정성태2/11/20227036.NET Framework: 1153. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 avio_reading.c 예제 포팅파일 다운로드1
12963정성태2/11/20227794.NET Framework: 1152. C# - 화면 캡처한 이미지를 ffmpeg(FFmpeg.AutoGen)로 동영상 처리 (저해상도 현상 해결)파일 다운로드1
12962정성태2/9/20227640오류 유형: 793. 마이크로소프트 스토어 - 제품이 존재하지 않습니다. 재고가 없는 것일 수 있습니다.
12961정성태2/8/20227767.NET Framework: 1151. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 비디오 프레임의 크기 및 포맷 변경 예제(scaling_video.c) [7]파일 다운로드1
12960정성태2/8/20227189개발 환경 구성: 637. ffmpeg(FFmpeg.AutoGen)를 이용한 비디오 디코딩 예제(decode_video.c) - 세 번째 이야기
12959정성태2/7/20227893.NET Framework: 1150. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 비디오 디코딩 예제(decode_video.c) - 두 번째 이야기 [2]파일 다운로드1
12958정성태2/6/20227969.NET Framework: 1149. C# - ffmpeg(FFmpeg.AutoGen) - 비디오 프레임 디코딩 [2]파일 다운로드1
12957정성태2/6/20227584개발 환경 구성: 636. ffmpeg.exe를 이용해 planar 포맷의 데이터를 packed 형식으로 변환하는 방법? [2]
12956정성태2/4/20226821.NET Framework: 1148. C# - ffmpeg(FFmpeg.AutoGen) - decoding 과정 [2]파일 다운로드1
12955정성태2/4/20226214개발 환경 구성: 635. 비주얼 스튜디오에서 실행하던 ASP.NET Core (.NET Framework) 응용 프로그램을 명령행에서 실행하는 방법 (2)
12954정성태2/4/20226041VS.NET IDE: 173. 비주얼 스튜디오 - Output 창에 색상이 지정된 출력 결과가 "[39m[22m" 식의 문자로 나오는 문제
12953정성태2/2/20226298Linux: 48. Windows 11 + WSL 우분투 GUI 환경에서 한글 출력
12952정성태2/2/20226777.NET Framework: 1148. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 오디오 필터 예제(filter_audio.c)파일 다운로드1
12951정성태2/2/20226737.NET Framework: 1147. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 오디오 필터링 예제(filtering_audio.c)파일 다운로드1
12950정성태2/1/20226380.NET Framework: 1146. .NET 6에 추가되지 않은 Generic Math (예: INumber<T>)
12949정성태2/1/20226222.NET Framework: 1145. C# - ffmpeg(FFmpeg.AutoGen) - Codec 정보 열람 및 사용 준비파일 다운로드1
12948정성태1/30/20226350.NET Framework: 1144. C# - ffmpeg(FFmpeg.AutoGen) AVFormatContext를 이용해 ffprobe처럼 정보 출력파일 다운로드1
12947정성태1/30/20227497개발 환경 구성: 634. ffmpeg.exe - 기존 동영상 컨테이너에 다중 스트림을 추가하는 방법
12946정성태1/28/20226025오류 유형: 792. .NET Core - 로컬 개발 중에 docker 호스팅으로 바꾸는 경우 SQL 서버 접근 방법
... 16  17  18  19  20  21  22  23  24  25  [26]  27  28  29  30  ...