可可西

在Win10上编译LLVM

代码仓库:https://github.com/llvm/llvm-project

 

LLVM_TARGETS_TO_BUILD

-DLLVM_TARGETS_TO_BUILD="X86;PowerPC". The full list, as of March 2023, is: AArch64;AMDGPU;ARM;AVR;BPF;Hexagon;Lanai;LoongArch;Mips;MSP430;NVPTX;PowerPC;RISCV;Sparc;SystemZ;VE;WebAssembly;X86;XCore

-DLLVM_TARGETS_TO_BUILD=host   // 将编译当前机器的架构的二进制 on an x86_64 machine will include the X86 target.

To enable all of them, use: -DLLVM_TARGETS_TO_BUILD=all

 

LLVM_ENABLE_PROJECTS

full list:bolt;clang;clang-tools-extra;compiler-rt;cross-project-tests;libc;libclc;lld;lldb;mlir;openmp;polly;pstl

To enable all of them, use: LLVM_ENABLE_RUNTIMES=all

 

LLVM_ENABLE_RUNTIMES

full list:libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc;offload

To enable all of them, use: LLVM_ENABLE_RUNTIMES=all

 

CMAKE_BUILD_TYPE

This configures the optimization level for make or ninja builds.

Possible values:

Build Type

Optimizations

Debug Info

Assertions

Best suited for

Release

For Speed

No

No

Users of LLVM and Clang

Debug

None

Yes

Yes

Developers of LLVM

RelWithDebInfo

For Speed

Yes

No

Users that also need Debug

MinSizeRel

For Size

No

No

When disk space matters

更多详见:https://llvm.org/docs/CMake.html 

 

在windows上编译llvm

 

build.windows.clang.bat内容如下:

复制代码
setlocal enableextensions
set "ROOT_DIR=%~dp0"
set "PROJECT_DIR=%ROOT_DIR%\llvm"
set "path=%~dp0tools\bin;C:\Python36-32;%path%"
set "CLANG_BUILD_DIR=%ROOT_DIR%\build\windows"
set "CLANG_INSTALL_DIR=%ROOT_DIR%\install\windows"
mkdir %CLANG_BUILD_DIR%
set "LLVM_ENABLE_PROJECTS=clang;lld"
set "LLVM_TARGETS_TO_BUILD=X86;WebAssembly"
set "CMAKE_BUILD_TYPE=RelWithDebInfo"
set "LIBFFI_DIR=%ROOT_DIR%\..\cppvm\source\cppvm-libffi\install\windows\x86_64"
set "CMAKE_PARAM=-DLLVM_ENABLE_PROJECTS="%LLVM_ENABLE_PROJECTS%" -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_DOCS=OFF -DLLVM_ENABLE_LLD=On -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=On -DLLVM_TARGETS_TO_BUILD="%LLVM_TARGETS_TO_BUILD%" -DLLVM_ENABLE_FFI=ON -DFFI_INCLUDE_DIR=%LIBFFI_DIR%\include -DLLVM_ENABLE_DUMP=On -DFFI_LIBRARY_DIR=%LIBFFI_DIR%\lib -DLLVM_OPTIMIZED_TABLEGEN=ON -DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% -DCMAKE_INSTALL_PREFIX=%CLANG_INSTALL_DIR% %PROJECT_DIR%"
cmake.exe -S %PROJECT_DIR% -B %CLANG_BUILD_DIR% -G "Visual Studio 16 2019"  -A x64 -Thost=x64 -DLLVM_COMPILER_JOBS=14 -DCMAKE_C_FLAGS="/bigobj" -DCMAKE_CXX_FLAGS="/bigobj" %CMAKE_PARAM% 
cmake --build %CLANG_BUILD_DIR% --config "%CMAKE_BUILD_TYPE%" --target INSTALL -- /m
pause
复制代码

 

一些报错:

复制代码
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_prep_cif referenced in function "bool __cdecl ffiInvoke(void (__cdecl*)(void),class llvm::Function *,class llvm::ArrayRef
<struct llvm::GenericValue>,class llvm::DataLayout const &,struct llvm::GenericValue &)" (?ffiInvoke@@YA_NP6AXXZPEAVFunction@llvm@@V?$ArrayRef@UGenericValue@llvm@@@2@AEBVDataLayout@2@AEAUGenericValue@2@@Z) [G:\svn\llvm
-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_call referenced in function "bool __cdecl ffiInvoke(void (__cdecl*)(void),class llvm::Function *,class llvm::ArrayRef<str
uct llvm::GenericValue>,class llvm::DataLayout const &,struct llvm::GenericValue &)" (?ffiInvoke@@YA_NP6AXXZPEAVFunction@llvm@@V?$ArrayRef@UGenericValue@llvm@@@2@AEBVDataLayout@2@AEAUGenericValue@2@@Z) [G:\svn\llvm-pro
ject\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_void referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_typ 
e@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint8 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_ty 
pe@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint16 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint32 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint64 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_float referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_ty 
pe@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_double referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_pointer referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_ 
type@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
G:\svn\llvm-project\build\windows\RelWithDebInfo\bin\lli.exe : fatal error LNK1120: 10 unresolved externals [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
复制代码
复制代码
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_prep_cif referenced in function "bool __cdecl ffiInvoke(void (__cdecl*)(void),class llvm::Function *,class llvm::ArrayRef
<struct llvm::GenericValue>,class llvm::DataLayout const &,struct llvm::GenericValue &)" (?ffiInvoke@@YA_NP6AXXZPEAVFunction@llvm@@V?$ArrayRef@UGenericValue@llvm@@@2@AEBVDataLayout@2@AEAUGenericValue@2@@Z) [G:\svn\llvm 
-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_call referenced in function "bool __cdecl ffiInvoke(void (__cdecl*)(void),class llvm::Function *,class llvm::ArrayRef<str
uct llvm::GenericValue>,class llvm::DataLayout const &,struct llvm::GenericValue &)" (?ffiInvoke@@YA_NP6AXXZPEAVFunction@llvm@@V?$ArrayRef@UGenericValue@llvm@@@2@AEBVDataLayout@2@AEAUGenericValue@2@@Z) [G:\svn\llvm-pro
ject\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_void referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_typ 
e@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint8 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_ty 
pe@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint16 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint32 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint64 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_float referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_ty 
pe@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_double referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_pointer referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_ 
type@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
G:\svn\llvm-project\build\windows\RelWithDebInfo\bin\LLVM-C.dll : fatal error LNK1120: 10 unresolved externals [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
复制代码

 

原因是:使用了静态库版的ffi.lib,而在G:\svn\llvm-project\llvm\lib\ExecutionEngine\Interpreter\ExternalFunctions.cpp中引用ffi.h会将FFI_API定义为__declspec(dllimport),导致名字修饰都会带上__imp_前缀,从而找不到这些符号

复制代码
/* Need minimal decorations for DLLs to work on Windows.  GCC has
   autoimport and autoexport.  Always mark externally visible symbols
   as dllimport for MSVC clients, even if it means an extra indirection
   when using the static version of the library.
   Besides, as a workaround, they can define FFI_BUILDING if they
   *know* they are going to link with the static library.  */
#if defined _MSC_VER
# if defined FFI_BUILDING_DLL /* Building libffi.DLL with msvcc.sh */
#  define FFI_API __declspec(dllexport)
# elif !defined FFI_BUILDING  /* Importing libffi.DLL */
#  define FFI_API __declspec(dllimport)
# else                        /* Building/linking static library */
#  define FFI_API
# endif
#else
# define FFI_API
#endif
复制代码

 

解决办法:预定义FFI_BUILDING

add_definitions("-DFFI_BUILDING")

 

posted on   可可西  阅读(55)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2024-01-20 Process Explorer高级技巧
2022-01-20 标准光照模型

导航

统计信息

点击右上角即可分享
微信分享提示