I want to compile mlir-toy Chapter1. The address is : https://mlir.llvm.org/docs/Tutorials/Toy/Ch-1/
The source code can be found here : https://github.com/llvm/clangir/blob/main/mlir/examples/toy/Ch1/toyc.cpp
My local CMakeLists.txt is :
cmake_minimum_required(VERSION 3.20)
project(mlir-toy VERSION 0.0.0)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
find_package(MLIR REQUIRED CONFIG)
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(TableGen)
include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)
set(MLIRTOY_SRC_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
include_directories(${LLVM_INCLUDE_DIRS} ${MLIR_INCLUDE_DIRS} ${MLIRTOY_SRC_INCLUDE_DIR})
add_executable(mlir-toy src/main.cpp src/AST.cpp)
target_link_libraries(mlir-toy PRIVATE MLIRSupport)
But I build it failed.
The compile info is :
/usr/bin/ld: CMakeFiles/mlir-toy.dir/src/main.cpp.o:(.data.rel.ro._ZTIN4llvm2cl3optIN12_GLOBAL__N_16ActionELb0ENS0_6parserIS3_EEEE+0x18): undefined reference to `typeinfo for llvm::cl::Option'
/usr/bin/ld: CMakeFiles/mlir-toy.dir/src/main.cpp.o:(.data.rel.ro._ZTIN4llvm2cl6parserIN12_GLOBAL__N_16ActionEEE+0x10): undefined reference to `typeinfo for llvm::cl::generic_parser_base'
/usr/bin/ld: CMakeFiles/mlir-toy.dir/src/main.cpp.o:(.data.rel.ro._ZTIN4llvm2cl15OptionValueCopyIN12_GLOBAL__N_16ActionEEE+0x10): undefined reference to `typeinfo for llvm::cl::GenericOptionValue'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
My clang++ version is:
Ubuntu clang version 17.0.6 (++20231128094036+6009708b4367-1~exp1~20231128094051.72)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
I download the llvm-project in the : https://github.com/llvm/llvm-project
Build the mlir and install it in : mlir-toy/install
I want to build the mlir-toy successfully!