使用 LLVM MAC OS X 编译项目导致链接器错误

Compiling project with LLVM MAC OS X causes linker error

我用 brew 安装了 LLVM

brew install llvm

在测试 C++ 文件中:

#include <llvm/IR/Value.h>
#include <llvm/IR/IRBuilder.h>

int main()
{
    llvm::LLVMContext context;
    llvm::Module *module = new llvm::Module("module", context);

    return 0;
}

生成文件:

BIN=main
SRC_FILES=main.cpp
FLAGS := $(shell llvm-config --cxxflags --ldflags --libs)

CC=/usr/local/opt/llvm/bin/clang
CXX=$(CC)++

all:
        $(CXX) $(FLAGS) -o $(BIN) $(SRC_FILES)

当我运行make

它给我这个错误:

Undefined symbols for architecture x86_64:
  "_del_curterm", referenced from:
      llvm::sys::Process::FileDescriptorHasColors(int) in libLLVMSupport.a(Process.cpp.o)
  "_set_curterm", referenced from:
      llvm::sys::Process::FileDescriptorHasColors(int) in libLLVMSupport.a(Process.cpp.o)
  "_setupterm", referenced from:
      llvm::sys::Process::FileDescriptorHasColors(int) in libLLVMSupport.a(Process.cpp.o)
  "_tigetnum", referenced from:
      llvm::sys::Process::FileDescriptorHasColors(int) in libLLVMSupport.a(Process.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1

我做错了什么?

我最终需要 --system-libs 作为 llvm-config 命令中的标志:

FLAGS := $(shell llvm-config --cxxflags --ldflags --libs --system-libs)