Reputation: 445
I recently installed LLVM 7, and tried to include the necessary files to start a project using llvm library in CLion. However, it complains that some files are not found.
My CMakeLists.txt file has the following:
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})
I know the way am linking is wrong, but I don't know how to fix it. I let it like this, because CLion can find the defined libraries (so I can see when I call functions of the libraries that don't exist, and if it's available I get a pop-up).
Am currently getting the following error when I run the project:
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
The project structure is shown here
Any help on this, is greatly appreciated. Thanks.
Upvotes: 2
Views: 2720
Reputation: 344
I had a similar problem and the LLVM documentation: solved my issue.
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})
Upvotes: 2