编译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
实际上解决了这个问题。但我担心移除它不是一个通用的解决方案。
发布于 2020-07-22 00:37:59
我认为问题可能是$(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})
https://stackoverflow.com/questions/62946029
复制相似问题