Problem of use CallGraph

Hello,
       I want to traverse CallGraph

code segment:

    virtual void getAnalysisUsage(AnalysisUsage &AU) const
    {
      AU.addRequired<CallGraph>();
    }

    virtual bool runOnModule(Module &F)
    {
      CallGraph &g = getAnalysis<CallGraph>();
      for ( CallGraph::iterator i = g.begin(); i != g.end(); i++)
      {
        errs()<<"-----------------\n";
        errs()<<i->second->getFunction()->getName()<<"\n";
      }
      return false;
    }

Compile:
g++ -fPIC -shared `llvm-config --cxxflags` -o MPIAnalysis.so MPIAnalysis.cpp,

when I use following command to run:
opt -load ./MPIAnalysis.so -hello < main
it shows the error:

Hello,
       I want to traverse CallGraph

code segment:

                virtual void getAnalysisUsage(AnalysisUsage &AU) const
                {
                        AU.addRequired<CallGraph>();
                }

                virtual bool runOnModule(Module &F)
                {
                        CallGraph &g = getAnalysis<CallGraph>();
                        for ( CallGraph::iterator i = g.begin(); i != g.end(); i++)
                        {
                                errs()<<"-----------------\n";

You may try something like this:
                                   if (CallGraphNode *CGN = i->second)
                                      ... CGN->getFunction()->getName() ...

This is what you need:

#include “llvm/InitializePasses.h”

PassRegistry &Registry = *PassRegistry::getPassRegistry();
initializeBasicCallGraphPass(Registry);

-Welson

Well, I read http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-July/033133.html
again and consult the information about "external node" in CallGraph.
http://llvm.org/docs/doxygen/html/CallGraph_8h_source.html
CallGraph would build an external nodes, and it linked to all funtions
in module. But the node itself does not stand for any function.
i->second->getFunction() would return NULL.
I should read previous message more carefully.
Sorry for the my spam. :frowning: