0

I have below code and I am getting undefined reference to `StInit::instance()'

File StInit.h

class StInit
{
public:
static StInit* instance();
};

File StInit.cc

#include "StInit.h"

StInit*
StInit::instance()
{
    static StInit *myPtr = NULL;
    ......
    ......
    return myPtr;
}

File nm.cc

#include "StInit.h"
StInit* stor_init = StInit::instance();

I don't know why I am getting this error. How to resolve this error?

Zeta
  • 103,620
  • 13
  • 194
  • 236
eswaat
  • 733
  • 1
  • 13
  • 31

1 Answers1

0

You are probably not including the 2nd file StInit.cc into the binary, hence the linker error. I am not familiar with tup, but looking at the manual it seems you need to include both the files in the tup file.

Look at the last example in this documentation: http://gittup.org/tup/ex_a_first_tupfile.html, just copying it as is should get you going.

So change the Tupfile to:

: foreach *.c |> gcc -Wall -c %f -o %o |> %B.o
: *.o |> gcc %f -o %o |> hello

And hello should have both the files compiled and linked in.

Arindam
  • 342
  • 1
  • 12