views:

204

answers:

2

gph is a singleton class with no getInstance method

class gph 
{
public:

  static void newfun();
  static void newfun1();

   //...//

private:
   gph();

};

This class gets build into a static library

Now I have a Dll from where I need to access the static function . So class A is a part of a Dll

I have a C++ member function say

void A:: fun()
{

   gph::newfun() ;  //accessing a static function  : gives linker errors
}

On the other hand if I make fun() as static it doesnt give me any linker errors . But I do not want to make fun() as static

A: 

Most of what I work on deals with statically linked libraries, so this answer may not apply, but may clue you in to the problem. So based on that and what I'm looking at right now, my first thought would be to check that in the dll you're building, you've included the static library.

An unresolved symbol usually means that either the signature doesn't match or you're not including the necessary library. It varies from compiler to compiler, but most make you specify the library directory (sometimes denoted by -L in a command line) and the actual library to be linked in (sometimes denoted by -l).

Since I don't use DLL's that much, my understanding of them is similar to building an executable. If you use dynamic linking when you build, the path of the libraries you are linking to are embedded in your executable, so your executable size is smaller, but is dependent on the library path they are linked to on not moving.

So when you're building your DLL, make sure you've compiled the cpp for class gph and created a static library for it. Then when you use it in class A, you include the header and link in the library.

Gary
A: 

I think it is the calling convention issue.

Please try the following code:

class gph { public:

static void __cdecl newfun(); //...//

};

Cang Tran