Mac OS X上嘗試編譯CoreCLR原始碼

來源:互聯網
上載者:User

標籤:

CoreCLR登陸GitHub之後,體驗CoreCLR首當其衝的方式就是在自己的電腦上編譯它,昨天分別在Windows與Linux上成功編譯了CoreCLR,詳見:

1)Windows上成功編譯CoreCLR原始碼 ;

2)Linux上成功編譯CoreCLR原始碼 。

Windows與Linux上編譯成功之後,有一個擋不住的衝動——在Mac上編譯CoreCLR。雖然微軟目前優先考慮的是Windows與Linux兩個平台,CoreCLR的編譯暫時不支援Mac OS X,但我最期待的卻是在Mac OS X上編譯CoreCLR,而且編譯CoreCLR所需要的CMake與LLVM在Mac OS X上都有,嘗試一下是必須的。

於是,心動不如行動,開始了Mac OS X編譯CoreCLR之旅。

Build操作步驟如下:

1)簽出github上的CoreCLR程式碼程式庫: git clone https://github.com/dotnet/coreclr.git 

2)安裝cmake: brew install cmake 

3)運行build命令: sh build.sh 

3)build結果-失敗,錯誤資訊如下:

Unable to locate llvm-arFailed to generate native component build project!

錯誤資訊顯示找不到llvm-ar命令。

運行命令 clang --version ,確認LLVM 3.5已安裝:

Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)

運行命令 ls /usr/bin/llvm* ,的確沒有llvm-ar:

/usr/bin/llvm-g++/usr/bin/llvm-gcc

後來發現原來藏在 /usr/local/opt/llvm/bin/ 檔案夾中:

ls /usr/local/opt/llvm/bin/llvm-ar/usr/local/opt/llvm/bin/llvm-ar

但環境變數$PATH中沒有這個路徑,於是加上這個路徑:

export PATH=/usr/local/opt/llvm/bin:$PATH

添加之後,繼續build,“Unable to locate llvm-ar”錯誤消失。

但出現了新的錯誤:

-- The C compiler identification is AppleClang 6.0.0.6000056-- The CXX compiler identification is AppleClang 6.0.0.6000056-- Check for working C compiler: /usr/bin/clang-- Check for working C compiler: /usr/bin/clang -- works-- Detecting C compiler ABI info-- Detecting C compiler ABI info - done-- Check for working CXX compiler: /usr/bin/clang++-- Check for working CXX compiler: /usr/bin/clang++ -- works-- Detecting CXX compiler ABI info-- Detecting CXX compiler ABI info - doneCMake Error at CMakeLists.txt:317 (message):  Not Implemented!

查看CMakeLists.txt中的代碼:

if (IS_64BIT_BUILD EQUAL 1)  if (CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64)    add_definitions(-DDBG_TARGET_AMD64_UNIX)  endif (CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64)  add_definitions(-D_TARGET_AMD64_=1)  add_definitions(-DDBG_TARGET_AMD64)else (IS_64BIT_BUILD EQUAL 1)  # TODO: Support this  message(FATAL_ERROR "Not Implemented!") #line 317endif (IS_64BIT_BUILD EQUAL 1)

第317代碼是 message(FATAL_ERROR "Not Implemented!") 。分析這段if代碼塊,可以知道當作業系統是Mac OS X時,IS_64BIT_BUILD的值不為1,如果將之設定為1就可以避開這個錯誤。

於是順藤摸瓜,在CMakeLists.txt的第128行找到了設定IS_64BIT_BUILD的代碼:

elseif (CLR_CMAKE_PLATFORM_UNIX)    # Set flag to indicate if this will be a 64bit Linux build  if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)    set(IS_64BIT_BUILD 1)    endif (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)

當CLR_CMAKE_PLATFORM_UNIX為true的時候,會將IS_64BIT_BUILD的值設定為1。

繼續順藤摸瓜,在CMakeLists.txt的第7行找到了設定CLR_CMAKE_PLATFORM_UNIX的代碼:

if(CMAKE_SYSTEM_NAME STREQUAL Linux)    set(CLR_CMAKE_PLATFORM_UNIX 1)    set(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64 1)endif(CMAKE_SYSTEM_NAME STREQUAL Linux)

然後依葫蘆畫瓢,添加了針對Mac OS X的代碼:

# Mac OS Xif(CMAKE_SYSTEM_NAME STREQUAL Darwin)    set(CLR_CMAKE_PLATFORM_UNIX 1)    set(CLR_CMAKE_PLATFORM_UNIX_TARGET_AMD64 1)endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)

然後運行./build.sh編譯CoreCLR,終於將build.sh跑起來了。雖然也有一些報錯,但是build的執行沒有中斷:

Commencing CoreCLR Repo buildChecking pre-requisites...Commencing build of native components for amd64/debugInvoking cmake with arguments: /git/dotnet/coreclr DEBUGDetected Linux x86_64-- Configuring doneCMake Warning (dev):  Policy CMP0042 is not set: MACOSX_RPATH is enabled by default.  Run "cmake  --help-policy CMP0042" for policy details.  Use the cmake_policy command to  set the policy and suppress this warning.  MACOSX_RPATH is not specified for the following targets:   coreclr   mscordaccoreThis warning is for project developers.  Use -Wno-dev to suppress it.-- Generating done-- Build files have been written to: /git/dotnet/coreclr/binaries/CMakeExecuting make./build.sh: line 84: nproc: command not found[  0%] Building C object src/pal/tools/cppmunge/CMakeFiles/cppmunge.dir/cppmunge.c.o[  1%] [  1%] Built target palrt[  1%] Built target mdhotdata_fullBuilt target gcinfo/git/dotnet/coreclr/src/pal/tools/cppmunge/cppmunge.c:38:10: fatal error: ‘linux/limits.h‘ file not found#include <linux/limits.h>         ^[  1%] [  1%] Built target ildbsymlibBuilt target dbgutil[  2%] Built target corguids[  3%] Built target ceefgen

滿懷期望地等待著build的結果。。。

但是在build過程中,MacBook的CPU風扇突然呼呼作響,接著OS X系統停止回應,只能強制關機。

開機後再嘗試,在build過程中依然會讓Mac掛掉。接著進行多次嘗試,只要build,Mac必掛。

Mac OS X上編譯CoreCLR之旅因為這個暫時無法解決的問題而中斷。

雖然這次嘗試失敗了,但是在Mac OS X上編譯CoreCLR的癡心不改,在Mac OS X上開發.NET程式的期待不變!

Mac OS X上嘗試編譯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.