can't link with libLLVMSupport.a

Hi.

I’m trying to compile reduced clang “driver.cpp” - added printf for arguments - and i’m getting linking with libLLVMSupport.a error - no StringSaver class found.

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”

Error message:

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)

Checking libLLVM is found and contains CommandLine object data:

(found on -L path):

find …/llvm_34_local_installed2/lib/ -name “upport

…/llvm_34_local_installed2/lib//libLLVMSupport.a

(contains CommandLine.cpp object data):

ar -t …/llvm_34_local_installed2/lib//libLLVMSupport.a | grep CommandLine

CommandLine.cpp.o

The class StringSaver is declared in 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 inheritor is declared and implemented in self file (lib_cmd_builder.cpp):

namespace {

class StringSetSaver : public llvm::cl::StringSaver {

public:

StringSetSaver(std::setstd::string &Storage) : Storage(Storage) {}

const char *SaveString(const char *Str) LLVM_OVERRIDE {

return SaveStringInSet(Storage, Str);

}

private:

std::setstd::string &Storage;

};

}

So i can’t understand why i’m having this error.

Any thoughts?

i’ve also checked llvm-config output and it seems to be ok (contain -L and -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

You might try building your library with -fno-rtti, or clang without it.

– James

Hi, James.

Thanks for suggestion.

I’ve modified compile/link cmd and added -fno-rtti (clang++ -c ./exe_interpreter.cpp -o ./exe_interpreter2.o -fno-rtti) but no luck.
How can i analyze produced object file to make sure it contains all necessary information (rtti)?

Let me explain everything in brief.
I’ve copied lli tool source code and modified it a bit (renamed main()) to produce static library instead of executable. I’m able to compile it and link it so lib…a file. Then i’m trying to link it with LLVM libs and unfortunately StringSaver class code is not found in libLLVMSupport.a though i can see it contains according object file.

I can modify my lib and executable compile/link arguments as needed, so please suggest me what can be done as i’m in stuck.

Regards, Anton.

Oops. i’ve tried again and it helps!

Actually i can’t understand why -fno-rtti is not appended by ../llvm_34_local_installed2/bin/llvm-config --cxxflags but it’s needed in my case.
Thanks, James.