So I'm trying to follow along with the LLVM compiler tutorial and I'm trying to build the toy example using CMake instead of llvm-config
. Because of an issue with Ubuntu's packaging system, I've decided to build LLVM from source and link to that. So I followed the instructions here to build LLVM 3.7.1 from source. I copy-pasted the Chapter 3 source code from LLVM's examples/Kaleidoscope
directory (since the tutorial linked above recommends doing so for the specific version of LLVM you use) and attempted to build it with the following CMakeLists.txt
, adapted heavily from this:
cmake_minimum_required(VERSION 3.5.1)
project(llvm-test-project)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message(STATUS "LLVM built with RTTI? ${LLVM_ENABLE_RTTI}")
add_executable(toy toy.cpp)
set_property(TARGET toy PROPERTY CXX_STANDARD 11)
include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
llvm_map_components_to_libnames(llvm_libs core support)
target_link_libraries(toy ${llvm_libs})
message(STATUS "LLVM linked to: ${llvm_libs}")
However, when I try to configure and build it, I get the following linker error:
undefinted reference to `typeinfo for llvm:CmpInst`
After attempting to link to other libraries other than core and support, I decided to try re-building LLVM with RTTI enabled, and sure enough, it compiles and links successfully when I add -DLLVM_ENABLE_RTTI=ON
to the LLVM cmake
invocation.
Is it possible to build LLVM without RTTI and still successfully link it to the Kaleidoscope examples? It seems strange that RTTI would be needed without any mention of such from either the tutorial or the LLVM CMake documentation.