Thread: Linker typeinfo error

  1. #1
    Registered User
    Join Date
    May 2008

    Linker typeinfo error

    I have an odd linker error compiling with Clang.

    I'm actually trying to build a clang tool and I am linking against a freshly built set of clang libraries which I can verify do indeed have the virtual ~FrontendActionFactory definition in the source.

    undefined reference to 'typeinfo for clang::tooling::FrontendActionFactory'
    Building via cmake with the line:
    clang++ CMakeFiles/cxxcheck.dir/cxxcheck.cpp.o  -o cxxcheck -rdynamic -L/home/mm/local/lib -lclangTooling -lclang -lclangAnalysis -lclangARCMigrate -lclangAST -lclangBasic -lclangCodeGen -lclangDriver -lclangEdit -lclangFrontend -lclangFrontendTool -lclangLex -lclangParse -lclangRewrite -lclangSema -lclangSerialization -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangStaticAnalyzerFrontend -lLLVMCore -lLLVMSupport
    And my source, which is really nothing thus far:
    #include <clang/Frontend/FrontendActions.h>
    #include <clang/Tooling/Tooling.h>
    namespace tool = clang::tooling;
    struct FrontendActionFactory : tool::FrontendActionFactory {
        clang::FrontendAction* create() {
            return new clang::SyntaxOnlyAction;
    int main(int argc, const char** argv) {
        auto cdb = tool::FixedCompilationDatabase::loadFromCommandLine(argc, argv);
        std::vector<std::string> srcs;
        for(int i = 1; i < argc; ++i) {
        return tool::ClangTool(*cdb, srcs).run(new FrontendActionFactory);
    I'm thinking perhaps at a stretch this may be some RTTI issue?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    I'm not very familiar with Clang but here are some suggestions: from here it seems that FrontendActionFactory will go into the "clangTooling" library that you're linking with (at a guess). So you could try running that compile command manually and shifting the -lclangTooling backwards and forwards; linkers tend to be order-dependent so you may have to put -lclangTooling later on. Of course, you'd probably get undefined function errors rather than typeinfo errors if this were actually the problem.

    You could use the program "nm" on your CMakeFiles/cxxcheck.dir/cxxcheck.cpp.o file. "nm" prints all the symbols defined in an object file, and also all the undefined symbols that the linker is going to have to find elsewhere. Probably you'll have a lot of undefined symbols (marked "U" for "undefined"); grep for the ones involving FrontendActionFactory, then run nm on the libclangTooling.a and see if those symbols correspondingly exist. (They should be of type "T", or at least not "U".) If all the symbols seem to exist in the library, maybe it's an issue with different compilation flags.

    Personally I would try compiling the program manually, adding libraries until you get rid of all the linker errors. It may just be a build system hiccup. If you can still reproduce the issue I would contact the Clang folks directly: you may need extra compiler flags (especially since you seem to be building a Clang tool), or it may be a compiler bug. Did you try using an older/more stable version of Clang?

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I'm getting a linker error?
    By Jesse20ghet in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2011, 06:23 PM
  2. linker error
    By floxn in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2005, 01:06 AM
  3. Linker error using Dev-C++
    By boontune in forum C++ Programming
    Replies: 10
    Last Post: 12-17-2002, 05:47 AM
  4. Linker Error !!!!
    By CodeJerk in forum C++ Programming
    Replies: 9
    Last Post: 11-15-2002, 07:34 AM
  5. Linker error
    By dv007 in forum C Programming
    Replies: 8
    Last Post: 06-07-2002, 02:37 PM