Visual Studio 2017编译LLVM7.0

1、编译环境

Win7 64位

Visual studio 2017 15.6

Windows Kits 10.0.14393.0

 

2、源码

http://releases.llvm.org/download.html#7.0.0

2.1 llvm

llvm-7.0.0.src.tar.xz

解压至llvm

2.2 Clang

cfe-7.0.0.src.tar.xz

解压重新命名为:clang

放入:llvm/tools

2.3 clang-extra

clang-tools-extra-7.0.0.src.tar.xz

解压重新命名为:extra

放入:llvm/tools/clang/tools

2.4 LLD linker

lld-7.0.0.src.tar.xz

解压重新命名为:lld

放入:llvm/tools

2.5 Polly Loop Optimizer

lld-7.0.0.src.tar.xz

解压重新命名为:polly

放入:llvm/tools

2.6 Compiler-RT

compiler-rt-7.0.0.src.tar.xz

解压重新命名为:compiler-rt

放入:llvm/projects

2.7 Libomp

openmp-7.0.0.src.tar.xz

解压重新命名为:openmp

放入:llvm/projects

2.8 libcxx and libcxxabi

libcxx-7.0.0.src.tar.xz

libcxxabi-7.0.0.src.tar.xz

解压重新命名为:libcxx 、libcxxabi

放入:llvm/projects

2.9 Test Suite Source Code

test-suite-7.0.0.src.tar.xz

解压重新命名为:test-suite

放入:llvm/projects

 

3、编译准备

3.1 安装CMake

cmake-3.12.3-win32-x86.zip

最低版本要求:3.4.3

3.2 安装python

添加PATH

3.3 安装perl

strawberry-perl-5.28.0.1-32bit.msi

添加PATH

Visual Studio 2017编译LLVM7.0_第1张图片

3.4 生成sln

用CMake生成sln

 

4、编译

打开LLVM.sln,建议先查看5修正错误,选择ALL_BUILD生成即可。

Visual Studio 2017编译LLVM7.0_第2张图片

 

5、调试错误解决

5.1 clang_rt.asan-dynamic-i386

Visual Studio 2017编译LLVM7.0_第3张图片

Windows下,Compiler-RT Libraries\RTAsan.i386\asan_malloc_win.cc

中无MemalignFromLocalPool()函数,添加一个空的。

Visual Studio 2017编译LLVM7.0_第4张图片

void* MemalignFromLocalPool(uptr alignment, uptr size) {

return NULL;

}

解决问题。当然空函数对程序的影响未知。

5.2 clangDaemon

Clang libraries\clangDaemon\CodeComplete.h

Visual Studio 2017编译LLVM7.0_第5张图片

 

将文件编码另存为:

Visual Studio 2017编译LLVM7.0_第6张图片

Visual Studio 2017编译LLVM7.0_第7张图片

解决问题。

5.3 OMP

Visual Studio 2017编译LLVM7.0_第8张图片

后期生成事件语句错误:

setlocal

E:\LLVM\cmake-3.12.3-win32-x86\cmake-3.12.3-win32-x86\bin\cmake.exe -E make_directory E:/LLVM/llvm-7.0.0.src/projects/openmp/runtime/exports/common.50/include

if %errorlevel% neq 0 goto :cmEnd

E:\LLVM\cmake-3.12.3-win32-x86\cmake-3.12.3-win32-x86\bin\cmake.exe -E copy omp.h E:/LLVM/llvm-7.0.0.src/projects/openmp/runtime/exports/common.50/include

if %errorlevel% neq 0 goto :cmEnd

:cmEnd

endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone

:cmErrorLevel

exit /b %1

:cmDone

if %errorlevel% neq 0 goto :VCEnd

setlocal

E:\LLVM\cmake-3.12.3-win32-x86\cmake-3.12.3-win32-x86\bin\cmake.exe -E make_directory E:/LLVM/llvm-7.0.0.src/projects/openmp/runtime/exports/win_32.50/lib

if %errorlevel% neq 0 goto :cmEnd

E:\LLVM\cmake-3.12.3-win32-x86\cmake-3.12.3-win32-x86\bin\cmake.exe -E copy E:/LLVM/dist/bin/libomp.dll E:/LLVM/llvm-7.0.0.src/projects/openmp/runtime/exports/win_32.50/lib

if %errorlevel% neq 0 goto :cmEnd

:cmEnd

endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone

:cmErrorLevel

exit /b %1

:cmDone

if %errorlevel% neq 0 goto :VCEnd

将标红部分修改为:

E:\LLVM\cmake-3.12.3-win32-x86\cmake-3.12.3-win32-x86\bin\cmake.exe -E copy E:/LLVM/dist/bin/$(ConfigurationName)/libomp.dll

5.4 ompip

A、包含库路径错误

由于项目文件中:libomp.dll.lib路径有误。

Visual Studio 2017编译LLVM7.0_第9张图片

删除相应的文件,按如下目录添加,或修改

dist\projects\openmp\runtime\src\ompimp.vcxpro文件中:

Debug\libomp.dll.lib" />

Visual Studio 2017编译LLVM7.0_第10张图片

B、后期生成事件语句错误

setlocal

E:\LLVM\cmake-3.12.3-win32-x86\cmake-3.12.3-win32-x86\bin\cmake.exe -E make_directory E:/LLVM/llvm-7.0.0.src/projects/openmp/runtime/exports/win_32.50/lib

if %errorlevel% neq 0 goto :cmEnd

E:\LLVM\cmake-3.12.3-win32-x86\cmake-3.12.3-win32-x86\bin\cmake.exe -E copy E:/LLVM/dist/lib/libomp.lib E:/LLVM/llvm-7.0.0.src/projects/openmp/runtime/exports/win_32.50/lib

if %errorlevel% neq 0 goto :cmEnd

:cmEnd

endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone

:cmErrorLevel

exit /b %1

:cmDone

if %errorlevel% neq 0 goto :VCEnd

将标红部分修改为:

E:\LLVM\cmake-3.12.3-win32-x86\cmake-3.12.3-win32-x86\bin\cmake.exe -E copy E:/LLVM/dist/lib/$(ConfigurationName)/libomp.lib E:/LLVM/llvm-7.0.0.src/projects/openmp/runtime/exports/win_32.50/lib

你可能感兴趣的:(LLVM,VS2017,LLVM,7.0)