[英]Kaleidoscope Example Code Compile Errors on MacOS with LLVM(8|10)
Compiling kaleidoscope tutorial code fails with clang++ -g -O3 toy.cpp $(llvm-config --cxxflags) -std=c++17
(as the example goes) and outputs the following error:编译万花筒教程代码失败并出现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 were installed with brew install llvm
(version 10 when this question is posted), later changed to brew install llvm@8
. LLVM 是使用brew install llvm
的(发布此问题时为版本 10),后来更改为brew install llvm@8
。
Interesting thing is, removing header llvm/ADT/STLExtras.h
actually solves this.有趣的是,删除 header llvm/ADT/STLExtras.h
实际上解决了这个问题。 But I'm afraid removing this will not be a general solution.但恐怕删除它不会是一个通用的解决方案。
I think the problem might be that $(llvm-config --cxxflags)
doesn't work properly in macOS.我认为问题可能是$(llvm-config --cxxflags)
在 macOS 中无法正常工作。 I don't know exactly what it is with --cxxflags
, but I personally experienced a problem that $(llvm-config --libfiles)
didn't return the correct path to the shared library libLLVM
in macOS (that command worked in Linux anyway).我不知道--cxxflags
到底是什么,但我个人遇到了一个问题,即$(llvm-config --libfiles)
没有返回 macOS 中共享库libLLVM
的正确路径(该命令在 Linux反正)。
However, I suggest to use CMake, which you will need anyway when working with LLVM.但是,我建议使用 CMake,在使用 LLVM 时无论如何都需要它。 Below is a sample CMake code copied fromthe LLVM website .下面是从LLVM 网站复制的示例 CMake 代码。 I followed this CMake code and can compile my project in macOS.我遵循了这个 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})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.