LLVM Discussion Forums

Some errors when link llvm with cmake

I am following the tutorial of Kaleidoscope. And I meet some errors when linking.

Undefined symbols for architecture x86_64:
  "llvm::BasicBlock::BasicBlock(llvm::LLVMContext&, llvm::Twine const&, llvm::Function*, llvm::BasicBlock*)", referenced from:
      llvm::BasicBlock::Create(llvm::LLVMContext&, llvm::Twine const&, llvm::Function*, llvm::BasicBlock*) in IRGenerator.cpp.o
  "llvm::ConstantFP::get(llvm::LLVMContext&, llvm::APFloat const&)", referenced from:
      front::NumberAST::codegen() in IRGenerator.cpp.o
  "llvm::ReturnInst::ReturnInst(llvm::LLVMContext&, llvm::Value*, llvm::Instruction*)", referenced from:
      llvm::ReturnInst::Create(llvm::LLVMContext&, llvm::Value*, llvm::Instruction*) in IRGenerator.cpp.o
  "llvm::VectorType::get(llvm::Type*, llvm::ElementCount)", referenced from:
      llvm::CmpInst::makeCmpResultType(llvm::Type*) in IRGenerator.cpp.o
  "llvm::APFloatBase::IEEEdouble()", referenced from:
      llvm::APFloat::APFloat(double) in IRGenerator.cpp.o
  "llvm::APFloatBase::PPCDoubleDouble()", referenced from:
      bool llvm::APFloat::usesLayout<llvm::detail::IEEEFloat>(llvm::fltSemantics const&) in IRGenerator.cpp.o
      bool llvm::APFloat::usesLayout<llvm::detail::DoubleAPFloat>(llvm::fltSemantics const&) in IRGenerator.cpp.o
......

  "llvm::Function::BuildLazyArguments() const", referenced from:
      llvm::Function::CheckLazyArguments() const in IRGenerator.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [_Lang] Error 1
make[1]: *** [CMakeFiles/_Lang.dir/all] Error 2
make: *** [all] Error 2

IRGenerator.cpp is the codegen() implement file.
And my cmakelist is:

cmake_minimum_required(VERSION 3.17)

set(CMAKE_CXX_STANDARD 17)

find_package(LLVM REQUIRED CONFIG)

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

add_compile_options(-Wall -Werror)

include_directories(src)
include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
message(STATUS "Include Directory ${LLVM_INCLUDE_DIRS}")

file(GLOB_RECURSE SOURCES "src/*.cpp")

add_executable(_Lang ${SOURCES})
llvm_map_components_to_libnames(LLVM_LIBS all)
target_link_libraries(_Lang ${LLVM_LIBS})

Is there something wrong about the link options?

Thanks.