gpt4 book ai didi

c++ - 在 CLion 中包含 llvm 库的正确方法是什么?

转载 作者:行者123 更新时间:2023-12-01 14:58:55 29 4
gpt4 key购买 nike

我最近安装了 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

项目结构在这里显示 Project Structure

对此的任何帮助,将不胜感激。谢谢。

最佳答案

我遇到了类似的问题,LLVM documentation:解决了我的问题。

cmake_minimum_required(VERSION 3.4.3)
project(TestCmake)

find_package(LLVM REQUIRED CONFIG)

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

# Set your project compile flags.
# E.g. if using the C++ header files
# you will need to enable C++11 support
# for your compiler.

include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})

# Now build our tools
add_executable(simple-tool tool.cpp)

# Find the libraries that correspond to the LLVM components
# that we wish to use
llvm_map_components_to_libnames(llvm_libs support core irreader)

# Link against LLVM libraries
target_link_libraries(simple-tool ${llvm_libs})

关于c++ - 在 CLion 中包含 llvm 库的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54538020/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com