The variable has an internal relationship but is not defined

I have this .h file:

namespace{ class Invariant{ public: Invariant(z3::expr e,Instruction *i):Expr(e),I(i){ DenseMap<Instruction*,Invariant*> FunMap = Invariants[F]; } private: //static map static DenseMap<Function*, DenseMap<Instruction*,Invariant*> >Invariants; }; }//end of anonymous namespace 

When I compile clang it says:

 Invariant.h:46:65: warning: variable '<anonymous namespace>::Invariant::Invariants' has internal linkage but is not defined static DenseMap<Function*, DenseMap<Instruction*,Invariant*> >Invariants; ^ Invariant.h:26:48: note: used here DenseMap<Instruction*,Invariant*> FunMap = Invariants[F]; 

What is the problem?

+7
source share
1 answer

Just identify it. After defining the class, but until the end of the anonymous namespace, add this line:

 DenseMap<Function*, DenseMap<Instruction*,Invariant*> > Invariant::Invariants; 

This will create a static member in each translation unit that includes this title (which is good because it is in an anonymous namespace that is unique to each translation unit). This is probably not what you want, but it follows from the definition of Invariant in the anonymous namespace. If you use a named namespace instead, you can put the Invariants definition in the source file and have only one object common to all the code.

+6
source

All Articles