我正在尝试编译简化的clang“driver.cpp” - 为参数添加了printf - 我正在使用libLLVMSupport.a链接错误 - 找不到StringSaver类。
# lib
echo "compiling cmd builder (x86_64) ..."
clang++ `../llvm_34_local_installed2/bin/llvm-config --cxxflags` -I ../llvm_34/tools/clang/include -I ../llvm_34_build_local2/tools/clang/include -c ./lib_cmd_builder.cpp -o ./lib_cmd_builder_x86_64.o
echo "linking cmd builder (x86_64) ..."
CMD="clang++ `../llvm_34_local_installed2/bin/llvm-config --ldflags` ./lib_cmd_builder_x86_64.o -o exe_cmd_builder_x86_64 `../llvm_34_local_installed2/bin/llvm-config --libs` -lclangARCMigrate -lclangAST -lclangASTMatchers -lclangAnalysis -lclangApplyReplacements -lclangBasic -lclangCodeGen -lclangDriver -lclangDynamicASTMatchers -lclangEdit -lclangFormat -lclangFrontend -lclangFrontendTool -lclangIndex -lclangLex -lclangParse -lclangQuery -lclangRewriteCore -lclangRewriteFrontend -lclangSema -lclangSerialization -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangStaticAnalyzerFrontend -lclangTidy -lclangTidyGoogleModule -lclangTidyLLVMModule"
echo "[${CMD}]"
${CMD}
错误讯息:
Undefined symbols for architecture x86_64:
"typeinfo for llvm::cl::StringSaver", referenced from:
typeinfo for (anonymous namespace)::StringSetSaver in lib_cmd_builder_x86_64.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
检查libLLVM并找到并包含CommandLine对象数据:
(在-L路径上找到):
find ../llvm_34_local_installed2/lib/ -name "*upport*"
../llvm_34_local_installed2/lib//libLLVMSupport.a
(包含CommandLine.cpp对象数据):
ar -t ../llvm_34_local_installed2/lib//libLLVMSupport.a | grep CommandLine
CommandLine.cpp.o
StringSaver类在CommandLine.cpp中声明:
/Users/asmirnov/Documents/dev/src/llvm_34/include/llvm/Support/CommandLine.h
class StringSaver {
virtual void anchor();
public:
virtual const char *SaveString(const char *Str) = 0;
virtual ~StringSaver() {}; // Pacify -Wnon-virtual-dtor.
};
StringSaver继承者在自身文件(lib_cmd_builder.cpp)中声明并实现:
namespace {
class StringSetSaver : public llvm::cl::StringSaver {
public:
StringSetSaver(std::set<std::string> &Storage) : Storage(Storage) {}
const char *SaveString(const char *Str) LLVM_OVERRIDE {
return SaveStringInSet(Storage, Str);
}
private:
std::set<std::string> &Storage;
};
}
我还检查了llvm-config输出,它似乎没问题(包含-L和-lLLVMSupport):
clang++ -L/Users/asmirnov/Documents/dev/src/llvm_34_local_installed2/lib -lcurses -lpthread -lz ./lib_cmd_builder_x86_64.o -o exe_cmd_builder_x86_64 -lLLVMInstrumentation -lLLVMIRReader -lLLVMAsmParser -lLLVMDebugInfo -lLLVMOption -lLLVMLTO -lLLVMLinker -lLLVMipo -lLLVMVectorize -lLLVMBitWriter -lLLVMBitReader -lLLVMTableGen -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMXCoreAsmPrinter -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMSystemZDisassembler -lLLVMSystemZCodeGen -lLLVMSystemZAsmParser -lLLVMSystemZDesc -lLLVMSystemZInfo -lLLVMSystemZAsmPrinter -lLLVMSparcCodeGen -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMR600CodeGen -lLLVMR600Desc -lLLVMR600Info -lLLVMR600AsmPrinter -lLLVMPowerPCCodeGen -lLLVMPowerPCAsmParser -lLLVMPowerPCDesc -lLLVMPowerPCInfo -lLLVMPowerPCAsmPrinter -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMNVPTXAsmPrinter -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMMSP430AsmPrinter -lLLVMMipsDisassembler -lLLVMMipsCodeGen -lLLVMMipsAsmParser -lLLVMMipsDesc -lLLVMMipsInfo -lLLVMMipsAsmPrinter -lLLVMHexagonCodeGen -lLLVMHexagonAsmPrinter -lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMCppBackendCodeGen -lLLVMCppBackendInfo -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMAArch64Disassembler -lLLVMAArch64CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMAArch64AsmParser -lLLVMAArch64Desc -lLLVMAArch64Info -lLLVMAArch64AsmPrinter -lLLVMAArch64Utils -lLLVMMCDisassembler -lLLVMMCParser -lLLVMInterpreter -lLLVMMCJIT -lLLVMJIT -lLLVMCodeGen -lLLVMObjCARCOpts -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMExecutionEngine -lLLVMTarget -lLLVMMC -lLLVMObject -lLLVMCore -lLLVMSupport -lclangARCMigrate -lclangAST -lclangASTMatchers -lclangAnalysis -lclangApplyReplacements -lclangBasic -lclangCodeGen -lclangDriver -lclangDynamicASTMatchers -lclangEdit -lclangFormat -lclangFrontend -lclangFrontendTool -lclangIndex -lclangLex -lclangParse -lclangQuery -lclangRewriteCore -lclangRewriteFrontend -lclangSema -lclangSerialization -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangStaticAnalyzerFrontend -lclangTidy -lclangTidyGoogleModule -lclangTidyLLVMModule
还检查了它是x86_64(我的主机设备)的构建:
lipo -info ../llvm_34_local_installed2/lib/libLLVMSupport.a
input file ../llvm_34_local_installed2/lib/libLLVMSupport.a is not a fat file
Non-fat file: ../llvm_34_local_installed2/lib/libLLVMSupport.a is architecture: x86_64
答案 0 :(得分:0)
编译库源时我必须使用-fno-rtti