Guessing here, but I think the Codegen method is a "key" method.
Normally the compiler emits weak definitions for things like inline
functions, vtables, and other data associated with the class
definition, but if it spots a key method definition, rather than
duplicating all that crap in every translation unit, it will trust
that whichever TU defines any key method will emit the vtable and the
rest of the data.
See if providing a definition of Codegen in a .cpp file fixes your problem.
Reid
On Mon, Feb 7, 2011 at 8:35 PM, Anton Skvorts <anton.skvorts at gmail.com>
wrote:> Hello all,
>
> When extending the tutorial to support global variables I'm getting
> the following linker error:
>
> glob.o:glob.cpp:(.text+0x12241): undefined reference to `vtable for
> GlobalExprAST'
> collect2: ld returned 1 exit status
>
> GlobalExprAST class is:
>
> /// GlobalExprAST - Expression class for globals
> class GlobalExprAST : public ExprAST {
> std::string Name;
> ExprAST *Init;
> public:
> GlobalExprAST(const std::string &name, ExprAST *init)
> : Name(name), Init(init) {}
>
> virtual Value *Codegen();
> };
>
>
> /// Parser
> /// ::= 'global' identifier ('=' expression)?
> static ExprAST *ParseGlobalExpr() {
> getNextToken();
>
> std::string Name = IdentifierStr;
> getNextToken();
>
> ExprAST *Init = 0;
> if (CurTok == '=') {
> getNextToken();
>
> Init = ParseExpression();
> if (Init == 0) return 0;
> }
> return new GlobalExprAST(Name, Init);
> }
>
> Any help would be much appreaciated!
> Anton
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>