如何使用LLVM目标初始化函数
我的主机系统
:默认目标:X86_64-Ingnown-linux-gnu
:主机CPU:Skylake
llvm/clang使用llvm_targets_to_build =所有选项。
如何在我的代码中使用另一个目标的初始化函数?
我修改了klee(符号执行工具)以运行跨平台目标的IR。
#include "llvm/Support/TargetSelect.h"
int main () {
...
// llvm::InitializeAllTargets(); -> Error
llvm::InitializeNativeTargets(); -> Success
...
}
在这种情况下,错误
${LLVM}/build/include/llvm/Config/Targets.def:28: undefined reference to `LLVMInitializeARMTargetInfo'
${LLVM}/build/include/llvm/Config/Targets.def:29: undefined reference to `LLVMInitializeBPFTargetInfo'
...
My Host System
: Default target: x86_64-unknown-linux-gnu
: Host CPU: skylake
LLVM/Clang built with LLVM_TARGETS_TO_BUILD=all option.
How to Use another target's Initialize Function in My code?
I modifying klee (symbolic execution tool) to run cross-platform Target's IR.
#include "llvm/Support/TargetSelect.h"
int main () {
...
// llvm::InitializeAllTargets(); -> Error
llvm::InitializeNativeTargets(); -> Success
...
}
In this case, error
${LLVM}/build/include/llvm/Config/Targets.def:28: undefined reference to `LLVMInitializeARMTargetInfo'
${LLVM}/build/include/llvm/Config/Targets.def:29: undefined reference to `LLVMInitializeBPFTargetInfo'
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

llvminitializexxxtargetInfo()函数由 initializealltargets()使用,错误消息暗示您没有链接所需的LLVM库。
initializenativetargets()成功了,因为您可能没有在-dllvm_targets_to_build中包含本机拱门。
您可以在cmakelists.txt中添加以下行以链接llvm目标库:
The LLVMInitializexxxTargetInfo() functions are used by InitializeAllTargets(), and the error message implys that you didn't link the required LLVM libraries.
InitializeNativeTargets() succeeded, because you maybe did't include your native arch in -DLLVM_TARGETS_TO_BUILD.
You can add the following lines in your CMakeLists.txt to link LLVM Targets libraries: