【发布时间】:2019-02-05 15:40:54
【问题描述】:
我最近安装了 LLVM 7,并尝试包含必要的文件以在 CLion 中使用 llvm 库启动项目。 但是,它抱怨找不到某些文件。
我的 CMakeLists.txt 文件包含以下内容:
cmake_minimum_required(VERSION 3.12)
project(TestCmake)
set(CMAKE_CXX_STANDARD 11)
link_directories(llvm/build/include/) # linked wrongly..
include_directories(llvm/llvm/include/) #linked wrongly.
set(BUILD_2 main_2)
set(SOURCE_FILES_2
# testing. llvm files.
tests/codegen_tests/fac.cpp
)
add_executable(${BUILD_2} ${SOURCE_FILES_2})
我知道链接的方式是错误的,但我不知道如何解决它。 我让它这样,因为 CLion 可以找到定义的库(所以我可以看到我何时调用不存在的库的函数,如果它可用,我会弹出一个窗口)。
当前运行项目时出现以下错误:
In file included from c4/llvm/llvm/include/llvm/IR/Module.h:23:0,
from c4/tests/codegen_tests/fac.cpp:1:
c4/llvm/llvm/include/llvm/IR/Attributes.h:74:38: fatal error: llvm/IR/Attributes.inc: No such file or directory
compilation terminated.
CMakeFiles/main_2.dir/build.make:62: recipe for target 'CMakeFiles/main_2.dir/tests/codegen_tests/fac.cpp.o' failed
make[3]: *** [CMakeFiles/main_2.dir/tests/codegen_tests/fac.cpp.o] Error 1
CMakeFiles/Makefile2:109: recipe for target 'CMakeFiles/main_2.dir/all' failed
make[2]: *** [CMakeFiles/main_2.dir/all] Error 2
CMakeFiles/Makefile2:121: recipe for target 'CMakeFiles/main_2.dir/rule' failed
make[1]: *** [CMakeFiles/main_2.dir/rule] Error 2
Makefile:153: recipe for target 'main_2' failed
make: *** [main_2] Error 2
对此的任何帮助,我们将不胜感激。谢谢。
【问题讨论】:
-
如that question 的cmets 中所述,文件
llvm/IR/Attributes.inc是生成的,因此它不在llvm source 目录下.假设您已经 安装了 llvm,您需要调用include_directories以获取安装前缀下的目录(类似于llvm/install/include/)。 -
@Tsyvarev。谢谢你的评论。我试过我得到未定义的引用错误,例如:
undefined reference to llvm::Value::setName(llvm::Twine const&)。此外,我尝试包括 build、install、llvm(没有构建或安装)。但我通常会遇到相同类型的错误。如果我使用make(我们有一个makefile),它可以通过终端工作。但我想使用 CLion 运行和调试。 -
像往常一样,“未定义的引用”错误通过链接适当的库来解决。在 CMake 中,使用
target_link_libraries命令执行链接。 -
我一直在尝试了解如何将
target_link_libraries()与 llvm 一起使用。你能给出一个如何使用它的示例代码吗?我不明白要将其链接到哪些文件/二进制文件。