同时使用带有检查器的Makefile构建clang

同时使用带有检查器的Makefile构建clang

本文介绍了链接器错误,同时使用带有检查器的Makefile构建clang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在连结阶段遇到问题。

I'm facing a problem during the linking phase.

我要做什么?

我想添加一个检查器铛。我从源代码构建LLVM和libc ++(是的,一些测试失败在libcxx测试后构建)。为了识别libc ++库,我将以下代码添加到Clang的根目录Makefile

I'm trying to add a checker to clang. I built LLVM and libc++ from the source code (Yes, some test failed during libcxx testing after build). To identify the libc++ library, I added the following code to the Clang's root directory Makefile

CXX.Flags += -stdlib=libc++
CXX.Flags += -std=c++11
CXX.Flags += -nostdinc++
CXX.Flags += -I/path/to/my/own/c++library/libcxx/include
LD.Flags += -L/path/to/my/own/c++library/libcxx/lib

链接器问题如下所示。

Undefined symbols for architecture x86_64:
"std::__1::__shared_weak_count::__get_deleter(std::type_info const&) const", referenced from:
      vtable for std::__1::__shared_ptr_p-traits<char> >& std::__1::operator<<<std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::regex_traits<char>::__init() in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  "std::__1::ios_base::getloc() const", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  "std::__1::__get_classname(char const*, bool)", referenced from:
      unsigned int std::__1::regex_traits<char>::__lookup_classname<char const*>(char const*, char const*, bool, char) const in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  "std::__1::__shared_weak_count::__add_shared()", referenced from:
      std::__1::basic_regex<char, std::__1::regex_traits<char> >::basic_regex(std::__1::basic_regex<char, std::__1::regex_traits<char> > const&) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  "std::__1::__shared_weak_count::__release_shared()", referenced from:
      std::__1::shared_ptr<std::__1::__empty_state<char> >::~shared_ptr() in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  "std::__1::__shared_weak_count::~__shared_weak_count()", referenced from:
      std::__1::__shared_ptr_pointer<std::__1::__empty_state<char>*, std::__1::default_delete<std::__1::__empty_state<char> >, std::__1::allocator<std::__1::__empty_state<char> > >::~__shared_ptr_pointer() in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  "std::__1::__get_collation_name(char const*)", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::regex_traits<char>::__lookup_collatename<char const*>(char const*, char const*, char) const in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::regex_traits<char>::__lookup_collatename<char*>(char*, char*, char) const in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  "std::__1::cout", referenced from:
      (anonymous namespace)::ObjCSelfInitChecker::checkPreStmt(clang::ObjCStringLiteral const*, clang::ento::CheckerContext&) const in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  "std::__1::ctype<char>::id", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::regex_traits<char>::__init() in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  "std::__1::locale::locale(std::__1::locale const&)", referenced from:
      std::__1::basic_regex<char, std::__1::regex_traits<char> >::__start_matching_list(bool) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::regex_traits<char>::regex_traits(std::__1::regex_traits<char> const&) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  "std::__1::locale::locale()", referenced from:
      std::__1::regex_traits<char>::regex_traits() in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  "std::__1::locale::~locale()", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::regex_traits<char>::~regex_traits() in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::basic_regex<char, std::__1::regex_traits<char> >::__start_matching_list(bool) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  "std::__1::collate<char>::id", referenced from:
      std::__1::regex_traits<char>::__init() in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  "std::__1::ios_base::clear(unsigned int)", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::basic_ostream<char, std::__1::char_traits<char> >::put(char) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::basic_ostream<char, std::__1::char_traits<char> >::flush() in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry() in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<<<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  "vtable for std::__1::__shared_count", referenced from:
      std::__1::shared_ptr<std::__1::__empty_state<char> >::shared_ptr<std::__1::__empty_state<char>, void>(std::__1::__empty_state<char>*) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for std::__1::__shared_weak_count", referenced from:
      std::__1::shared_ptr<std::__1::__empty_state<char> >::shared_ptr<std::__1::__empty_state<char>, void>(std::__1::__empty_state<char>*) in libclangStaticAnalyzerCheckers.a(ObjCSelfInitChecker.o)
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [/Users/msecurity/Documents/Deepak/Eclipse/clang_build/build/Debug+Asserts/bin/clang] Error 1
make[1]: *** [driver/.makeall] Error 2
make: *** [all] Error 1



我按照链接器的建议使用-v选项请参阅链接器调用,并获得以下输出。

I followed the linker's suggestion to use -v option to see linker invocation, and got the following output.

"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o /path/to/onw/clang/build/Debug+Asserts/bin/clang -L/path/to/onw/clang//build/Debug+Asserts/lib -L/path/to/onw/clang/build/Debug+Asserts/lib -L/path/to/libc++/build/libcxx/lib -rpath @executable_path/../lib -sectcreate __TEXT __info_plist /path/to/onw/clang/build/tools/clang/tools/driver/Debug+Asserts/Info.plist /path/to/onw/clang/build/tools/clang/tools/driver/Debug+Asserts/cc1_main.o /path/to/onw/clang/build/tools/clang/tools/driver/Debug+Asserts/cc1as_main.o /path/to/onw/clang/build/tools/clang/tools/driver/Debug+Asserts/driver.o -lclangFrontendTool -lclangFrontend -lclangDriver -lclangSerialization -lclangCodeGen -lclangParse -lclangSema -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangARCMigrate -lclangRewriteFrontend -lclangRewriteCore -lclangAnalysis -lclangEdit -lclangAST -lclangBasic -lclangLex -lLLVMOption -lLLVMLinker -lLLVMIRReader -lLLVMipo -lLLVMVectorize -lLLVMInstrumentation -lLLVMBitWriter -lLLVMBitReader -lLLVMAsmParser -lLLVMR600CodeGen -lLLVMR600Desc -lLLVMR600Info -lLLVMR600AsmPrinter -lLLVMSystemZDisassembler -lLLVMSystemZCodeGen -lLLVMSystemZAsmParser -lLLVMSystemZDesc -lLLVMSystemZInfo -lLLVMSystemZAsmPrinter -lLLVMHexagonCodeGen -lLLVMHexagonAsmPrinter -lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMNVPTXAsmPrinter -lLLVMCppBackendCodeGen -lLLVMCppBackendInfo -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMMSP430AsmPrinter -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMXCoreAsmPrinter -lLLVMMipsDisassembler -lLLVMMipsCodeGen -lLLVMMipsAsmParser -lLLVMMipsDesc -lLLVMMipsInfo -lLLVMMipsAsmPrinter -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMAArch64Disassembler -lLLVMAArch64CodeGen -lLLVMAArch64AsmParser -lLLVMAArch64Desc -lLLVMAArch64Info -lLLVMAArch64AsmPrinter -lLLVMAArch64Utils -lLLVMPowerPCCodeGen -lLLVMPowerPCAsmParser -lLLVMPowerPCDesc -lLLVMPowerPCInfo -lLLVMPowerPCAsmPrinter -lLLVMSparcCodeGen -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMMCParser -lLLVMCodeGen -lLLVMObjCARCOpts -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMX86Desc -lLLVMX86Info -lLLVMTarget -lLLVMX86AsmPrinter -lLLVMMC -lLLVMObject -lLLVMX86Utils -lLLVMCore -lLLVMSupport -lz -lpthread -lcurses -lm -lstdc++ -lSystem /usr/bin/../lib/clang/4.2/lib/darwin/libclang_rt.osx.a

我观察到它使用我为它构建的C ++ 11库,因为它是上述调用中的ld的第6个选项。有没有其他选择,我应该照顾?

I observed that it's using the C++11 library that I built for it, as it is the 6th option to ld in above invocation. Is there any other options that I should take care of ?

我试图google出来,如果任何解决方案是可用的,我发现这种缺少vtable条目的问题非内联虚拟函数存在于早期版本的llvm中,并且使用最新版本帮助其他人。但我已经使用llvm最新版本。以下是clang -v输出

I tried to google out if any solution is available, and I found this kind of problem of missing vtable entries for non-inline virtual function existed in the earlier versions of llvm, and using the latest version helped others. But I'm already using llvm latest version. The following is the clang -v output


clang version 3.4 (trunk 192102) (llvm/trunk 192100)
Target: x86_64-apple-darwin12.3.0
Thread model: posix

请指导我解决问题的可能方法。让我知道,如果我需要分享任何更多的细节。如果我有任何方式,违反任何约定或规范(这是我对StackOverflow的第一个问题),对不起,请允许我知道。

Please guide me with the possible way to solve the problem. Let me know if I need to share any more details. If I'm any way, violating any conventions or norms(this is my first question on StackOverflow), I'm sorry for that, and kindly let me know.

请注意:我之前添加了一个检查器,它工作正常,并完成了我的目的。当我尝试包含标准C ++头来扩展同一个检查器时,会出现上述所有问题。

推荐答案

正如你可以在链接器cmdline中看到的,您尝试使用libstdc ++(-lstdc ++)链接。所以,你将使用libc ++编译的对象与libstdc ++

As you can see in the linker cmdline, you're trying to link using libstdc++ (-lstdc++). So, you're mixing the objects compiled with libc++ with libstdc++

这篇关于链接器错误,同时使用带有检查器的Makefile构建clang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 19:53