在Linux CentOS上編譯CoreCLR

來源:互聯網
上載者:User

在Linux CentOS上編譯CoreCLR

經過幾天的努力,終於解決了在CentOS上編譯CoreCLR的問題。最終發現問題是CMAKE_C_FLAGS的設定引起的。

只要在“src/pal/tools/clang-compiler-override.txt”中刪除“SET (CMAKE_C_FLAGS_INIT "-Wall -std=c11") ”,在“src/pal/tests/CMakeLists.txt”中添加“SET (CMAKE_C_FLAGS "-Wall -std=c11")”,就能編譯了。(更新:後來找到一個更好的解決方案:只需要將-std=c11改為-std=gnu11) 

下面分享一下在CentOS上編譯CoreCLR的操作步驟。

所用的CentOS版本7.0。

1)下載llvm的原始碼

wget http://llvm.org/releases/3.5.0/llvm-3.5.0.src.tar.xzmv llvm-3.5.0.src llvm

2)下載clang的原始碼

cd llvm/toolswget http://llvm.org/releases/3.5.0/cfe-3.5.0.src.tar.xztar xf cfe-3.5.0.src.tar.xzmv cfe-3.5.0.src clang

2+)下載lldb的原始碼及安裝相關組件

wget http://llvm.org/releases/3.5.0/lldb-3.5.0.src.tar.xztar -xf lldb-3.5.0.src.tar.xzmv lldb-3.5.0.src lldbyum install swig python-devel libedit-devel

3)下載compiler-rt的原始碼

cd ../projectswget http://llvm.org/releases/3.5.0/compiler-rt-3.5.0.src.tar.xztar xf compiler-rt-3.5.0.src.tar.xzmv compiler-rt-3.5.0.src compiler-rt

4)下載libcxxabi的原始碼

wget http://llvm.org/releases/3.5.0/libcxxabi-3.5.0.src.tar.xztar -xf libcxxabi-3.5.0.src.tar.xzmv libcxxabi-3.5.0.src.tar.xz libcxxabi

5)下載libcxx的原始碼

wget http://llvm.org/releases/3.5.0/libcxx-3.5.0.src.tar.xztar xf  libcxx-3.5.0.src.tar.xzmv libcxx-3.5.0.src libcxx

6)配置編譯選項

cd .../configure --enable-optimized CC=gcc CXX=g++

7)編譯llvm

make -j2

8)安裝編譯好的llvm

make install

(如果只安裝lldb,只需進入llvm/tools/lldb中運行make install)

9)簽出CoreClr的原始碼進行編譯

git clone https://github.com/dotnet/coreclr.gitcd coreclr./build.sh

10)安裝libunwind

wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gztar -xf libunwind-1.1.tar.gzcd libunwind-1.1./configuremakemake install

如果不安裝libunwind會出現下面的錯誤:

/data/git/coreclr/src/pal/src/exception/seh-unwind.cpp:32:10: fatal error: 'libunwind.h' file not found

10)解決"Native context type is not known"編譯錯誤

編譯過程中出現如下的錯誤:

-- Check size of siginfo_t-- Check size of siginfo_t - failed-- Check size of ucontext_t-- Check size of ucontext_t - failed...[  0%] Building CXX object src/palrt/CMakeFiles/palrt.dir/bstr.cpp.oIn file included from /data/git/coreclr/src/pal/src/arch/i386/context.cpp:25:/data/git/coreclr/src/pal/src/include/pal/context.h:40:2: error: Native context type is not known on this platform!

修改 src/pal/tools/clang-compiler-override.txt 檔案,去掉 SET (CMAKE_C_FLAGS_INIT "-Wall -std=c11") 可以解決這個問題。

(更新:後來找到一個更好的解決方案:只需要將-std=c11改為-std=gnu11)

10)解決"use of undeclared identifier"編譯錯誤

繼續編譯過程中出現如下的錯誤:

/data/git/coreclr/src/pal/tests/palsuite/c_runtime/wprintf/test2/test2.c:31:15: error: use of undeclared      identifier 'u'    DoStrTest(u"foo %s", u"bar", u"foo bar");

在 src/pal/tests/CMakeLists.txt 中添加 SET (CMAKE_C_FLAGS "-Wall -std=c11") 可以解決這個問題。

(更新:後來找到一個更好的解決方案:只需要將-std=c11改為-std=gnu11)

11)大功告成

Repo successfully built.Product binaries are available at /data/git/coreclr/binaries/Product/amd64/debug

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.