简体   繁体   中英

Compiling project with LLVM MAC OS X causes linker error

I installed LLVM with brew

brew install llvm

in a test c++ file:

#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;
}

Makefile:

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)

When I run make

It gives me this error:

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

What am I doing wrong here?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM