Undefined symbols for architecture x86_64: “std::terminate()”, when building kaleidoscope llvm

不羁的心 提交于 2019-12-08 08:39:23

问题


I'm doing the kaleidoscope tutorial. I'm on step two.

https://github.com/westymatt/creole

But I get this error when building with clang++

clang++ -Wno-c++11-extensions -g -std=c++11  -I/usr/local/Cellar/llvm/3.6.1/include    -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS src/lexer.cc src/parser.cc -L/usr/local/Cellar/llvm/3.6.1/lib/ -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMCodeGen -lLLVMScalarOpts -lLLVMProfileData -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMX86Desc -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMMC -lLLVMX86Utils -lLLVMCore -lLLVMSupport -lc++ -O0 -o creole
Undefined symbols for architecture x86_64:
  "std::terminate()", referenced from:
      ___clang_call_terminate in lexer-608bbc.o
      ___clang_call_terminate in parser-09b617.o
ld: symbol(s) not found for architecture x86_64

回答1:


std::terminate is located inside libc++ on OSX (which I assume you're using because of the "Cellar" in your path there). You appear to be explicitly linking against libc++ which means that the ordering is likely going wrong on your link line.

I can't duplicate this using the actual tutorial sources from top of tree (I don't have 3.6.1 checked out), but I'd suggest you follow the example Makefiles in there. The link line for a given part of the tutorial looks like:

clang++ -Wl,-dead_strip -rdynamic -Wl,-rpath -Wl,@executable_path/../lib -L/Users/echristo/builds/build-llvm/Debug+Asserts/lib -L/Users/echristo/builds/build-llvm/Debug+Asserts/lib -m64 -o /Users/echristo/builds/build-llvm/Debug+Asserts/examples/Kaleidoscope-Ch4 /Users/echristo/builds/build-llvm/examples/Kaleidoscope/Chapter4/Debug+Asserts/toy.o \ -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMCodeGen -lLLVMScalarOpts -lLLVMProfileData -lLLVMInstCombine -lLLVMInstrumentation -lLLVMTransformUtils -lLLVMipa -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMMCJIT -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMMC -lLLVMCore -lLLVMSupport -lz -lpthread -ledit -lcurses -lm

which should give you an idea of what it'll look like.

From looking at your sources on github it looks like you've gone to a "include the output of llvm-config on the command line" which isn't very reliable as components may change, etc.

clang++ -g -O3 toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core` -o toy

from the tutorial should be enough to compile your simple example. Just replace toy.cpp with both of your example files since you split it up.




回答2:


I got this error, while I was linking my code with my static lib built with ARC but there were some Objective C file with .mm extension. When I rename them with .m, worked fine.




回答3:


According to this you need to make sure your implementations for your functions all have corresponding declarations.



来源:https://stackoverflow.com/questions/31152499/undefined-symbols-for-architecture-x86-64-stdterminate-when-building-kal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!