【问题标题】:Kaleidoscope Example Code Compile Errors on MacOS with LLVM(8|10)Kaleidoscope 示例代码在使用 LLVM 的 MacOS 上编译错误(8|10)
【发布时间】:2020-07-17 02:09:04
【问题描述】:

编译kaleidoscope tutorial code 失败并显示clang++ -g -O3 toy.cpp $(llvm-config --cxxflags) -std=c++17(如示例所示)并输出以下错误:

Undefined symbols for architecture x86_64:
  "llvm::DisableABIBreakingChecks", referenced from:
      llvm::VerifyDisableABIBreakingChecks in toy-e1a114.o
ld: symbol(s) not found for architecture x86_64
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)

LLVM 使用 brew install llvm 安装(发布此问题时为版本 10),后来更改为 brew install llvm@8

有趣的是,删除标题llvm/ADT/STLExtras.h 实际上解决了这个问题。但恐怕删除它不是一个通用的解决方案。

【问题讨论】:

    标签: c++ llvm-clang kaleidoscope


    【解决方案1】:

    我认为问题可能是$(llvm-config --cxxflags) 在 macOS 中无法正常工作。我不知道--cxxflags 到底是什么,但我个人遇到了一个问题,即$(llvm-config --libfiles) 没有在macOS 中返回共享库libLLVM 的正确路径(该命令无论如何都在Linux 中工作)。

    但是,我建议使用 CMake,在使用 LLVM 时无论如何都需要它。下面是从the LLVM website 复制的示例 CMake 代码。我遵循了这个 CMake 代码,可以在 macOS 中编译我的项目。

    cmake_minimum_required(VERSION 3.4.3)
    project(SimpleProject)
    
    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})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-21
      • 2019-09-22
      • 1970-01-01
      • 2012-04-14
      相关资源
      最近更新 更多