在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.xz mv llvm-3.5.0.src llvm
2)下载clang的源代码
cd llvm/tools wget http://llvm.org/releases/3.5.0/cfe-3.5.0.src.tar.xz tar xf cfe-3.5.0.src.tar.xz mv cfe-3.5.0.src clang
2+)下载lldb的源代码及安装相关组件
wget http://llvm.org/releases/3.5.0/lldb-3.5.0.src.tar.xz tar -xf lldb-3.5.0.src.tar.xz mv lldb-3.5.0.src lldb yum install swig python-devel libedit-devel
3)下载compiler-rt的源代码
cd ../projects wget http://llvm.org/releases/3.5.0/compiler-rt-3.5.0.src.tar.xz tar xf compiler-rt-3.5.0.src.tar.xz mv compiler-rt-3.5.0.src compiler-rt
4)下载libcxxabi的源代码
wget http://llvm.org/releases/3.5.0/libcxxabi-3.5.0.src.tar.xz tar -xf libcxxabi-3.5.0.src.tar.xz mv libcxxabi-3.5.0.src.tar.xz libcxxabi
5)下载libcxx的源代码
wget http://llvm.org/releases/3.5.0/libcxx-3.5.0.src.tar.xz tar xf libcxx-3.5.0.src.tar.xz mv 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.git cd coreclr ./build.sh
10)安装libunwind
wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz tar -xf libunwind-1.1.tar.gz cd libunwind-1.1 ./configure make make 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.o In 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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 推荐几款开源且免费的 .NET MAUI 组件库
· 实操Deepseek接入个人知识库
· 易语言 —— 开山篇
· Trae初体验
2013-02-19 解决VS2012 Express的"There was a problem sending the command to the program"问题
2006-02-19 SQL Server 2005与SQL Server 2000的兼容性
2004-02-19 如何修改日历的CSS
2004-02-19 今天的任务