1. 程式人生 > >Visual Studio 2017編譯LLVM7.0

Visual Studio 2017編譯LLVM7.0

1、編譯環境

Win7 64位

Visual studio 2017 15.6

Windows Kits 10.0.14393.0

2、原始碼

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

3.4 生成sln

用CMake生成sln

4、編譯

開啟LLVM.sln,建議先檢視5修正錯誤,選擇ALL_BUILD生成即可。

5、除錯錯誤解決

5.1 clang_rt.asan-dynamic-i386

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

中無MemalignFromLocalPool()函式,新增一個空的。

void* MemalignFromLocalPool(uptr alignment, uptr size) {

return NULL;

}

解決問題。當然空函式對程式的影響未知。

5.2 clangDaemon

Clang libraries\clangDaemon\CodeComplete.h

將檔案編碼另存為:

解決問題。

5.3 OMP

後期生成事件語句錯誤:

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路徑有誤。

刪除相應的檔案,按如下目錄新增,或修改

dist\projects\openmp\runtime\src\ompimp.vcxpro檔案中:

<Object Include="E:\LLVM\dist\lib\Debug\libomp.dll.lib" />

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