我从OpenSuse LLVM(3.9)开发环境迁移到MacOS High Sierra。我正在尝试为类C语言生成LLVM IR。在解决方案SO answer之后,我使用brew安装了最新的LLVM 7.0.0。 我的问题是以下makefile(-ll更改为-lfl)在OpenSuse上顺利运行,但在MacO上显示错误时失败。
_OBJS = reference_table.o symbol_table.o function.o log_expr.o expr.o decl.o statement.o translation.o
_COMMON = common.h
LLVMCONFIG = llvm-config
CPPFLAGS = -I/usr/local/opt/llvm/include `$(LLVMCONFIG) --cxxflags` -std=c++11 -g
LDFLAGS = -L/usr/local/opt/llvm/lib `$(LLVMCONFIG) --ldflags`
LIBS = -v `$(LLVMCONFIG) --libs` `$(LLVMCONFIG) --system-libs` -lm -lpthread -ldl
OBJS = $(patsubst %,tree/%,$(_OBJS))
COMMON = $(patsubst %,tree/%,$(_COMMON))
OBJS += c.tab.o c.lex.o cc.o
cc: $(OBJS)
clang++ $(OBJS) $(LDFLAGS) $(LIBS) -o $@
%.o: %.cpp
clang++ -c $(CPPFLAGS) $< -o $@
c.tab.cpp c.tab.hpp: c.y $(COMMON) defines.h
bison -o c.tab.cpp -d c.y
c.lex.cpp: c.l c.tab.hpp
flex -o c.lex.cpp -l c.l
clean:
rm -f c.tab.cpp c.tab.hpp c.lex.cpp cc c.output tree/*.o *.ll *.o
错误:
clang version 7.0.0 (https://llvm.org/git/clang.git 6efe17611a988cf2f4a78ab34b04f24ea7fc7dd9) (https://llvm.org/git/llvm.git 788c75b81c842cf8017f163a6e9433a40163084e)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
"/usr/bin/ld" -demangle -lto_library /usr/local/Cellar/llvm/HEAD-788c75b/lib/libLTO.dylib -dynamic -arch x86_64 -macosx_version_min 10.13.0 -o cc -L/usr/local/opt/llvm/lib -L/usr/local/Cellar/llvm/HEAD-788c75b/lib tree/reference_table.o tree/symbol_table.o tree/function.o tree/log_expr.o tree/expr.o tree/decl.o tree/statement.o tree/translation.o c.tab.o c.lex.o cc.o -search_paths_first -headerpad_max_install_names -lLLVMLTO -lLLVMPasses -lLLVMObjCARCOpts -lLLVMSymbolize -lLLVMDebugInfoPDB -lLLVMDebugInfoDWARF -lLLVMMIRParser -lLLVMFuzzMutate -lLLVMCoverage -lLLVMTableGen -lLLVMDlltoolDriver -lLLVMOrcJIT -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMXCoreAsmPrinter -lLLVMSystemZDisassembler -lLLVMSystemZCodeGen -lLLVMSystemZAsmParser -lLLVMSystemZDesc -lLLVMSystemZInfo -lLLVMSystemZAsmPrinter -lLLVMSparcDisassembler -lLLVMSparcCodeGen -lLLVMSparcAsmParser -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMSparcAsmPrinter -lLLVMPowerPCDisassembler -lLLVMPowerPCCodeGen -lLLVMPowerPCAsmParser -lLLVMPowerPCDesc -lLLVMPowerPCInfo -lLLVMPowerPCAsmPrinter -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMNVPTXAsmPrinter -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMMSP430AsmPrinter -lLLVMMipsDisassembler -lLLVMMipsCodeGen -lLLVMMipsAsmParser -lLLVMMipsDesc -lLLVMMipsInfo -lLLVMMipsAsmPrinter -lLLVMLanaiDisassembler -lLLVMLanaiCodeGen -lLLVMLanaiAsmParser -lLLVMLanaiDesc -lLLVMLanaiAsmPrinter -lLLVMLanaiInfo -lLLVMHexagonDisassembler -lLLVMHexagonCodeGen -lLLVMHexagonAsmParser -lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMBPFDisassembler -lLLVMBPFCodeGen -lLLVMBPFAsmParser -lLLVMBPFDesc -lLLVMBPFInfo -lLLVMBPFAsmPrinter -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMARMUtils -lLLVMAMDGPUDisassembler -lLLVMAMDGPUCodeGen -lLLVMAMDGPUAsmParser -lLLVMAMDGPUDesc -lLLVMAMDGPUInfo -lLLVMAMDGPUAsmPrinter -lLLVMAMDGPUUtils -lLLVMAArch64Disassembler -lLLVMAArch64CodeGen -lLLVMAArch64AsmParser -lLLVMAArch64Desc -lLLVMAArch64Info -lLLVMAArch64AsmPrinter -lLLVMAArch64Utils -lLLVMObjectYAML -lLLVMLibDriver -lLLVMOption -lLLVMWindowsManifest -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMGlobalISel -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMMCJIT -lLLVMLineEditor -lLLVMInterpreter -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMCodeGen -lLLVMTarget -lLLVMCoroutines -lLLVMipo -lLLVMInstrumentation -lLLVMVectorize -lLLVMScalarOpts -lLLVMLinker -lLLVMIRReader -lLLVMAsmParser -lLLVMInstCombine -lLLVMBitWriter -lLLVMAggressiveInstCombine -lLLVMTransformUtils -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMMCParser -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMDebugInfoMSF -lLLVMBitReader -lLLVMCore -lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle -lz -lcurses -lm -lxml2 -lm -lpthread -ldl -lc++ -lSystem /usr/local/Cellar/llvm/HEAD-788c75b/lib/clang/7.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"llvm::Type::dump() const", referenced from:
assignmentExpr::codeGen() in expr.o
"llvm::Module::dump() const", referenced from:
translationUnit::startCodeGen(translationUnit*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in translation.o
ld: symbol(s) not found for architecture x86_64
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [cc] Error 1
此外,如果我替换Module-&gt; dump(),Type-&gt; dump()调用它们的定义(Module-&gt; print(dbgs(),nullptr)),它编译并正常工作。< / p>
这些转储功能显示在7.0.0 here中。 我想我可能会做一些像makefile命令那样微不足道的错误,但到目前为止,我无法从一天开始。 任何帮助是极大的赞赏。提前谢谢!