0

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

5
  • 1
    If you get linker errors, then there is most likely a difference in your member function's signatures in declaration and definition (.cpp/.h). Feb 2, 2010 at 13:54
  • 4
    Can you tell us what the errors are
    – Yacoby
    Feb 2, 2010 at 13:55
  • 5
    You need to show us more code - for example, the definition of gph and its relationship with A.
    – anon
    Feb 2, 2010 at 13:59
  • @Yacoby That is the error error LNK2019: unresolved external symbolpublic: static void __cdecl gph::newfun Feb 2, 2010 at 14:06
  • 1
    Why have you not provided a return type for static newfun()? This code will not compile. Also why is this function declared twice? Please post the actual code, and format it correctly. Feb 2, 2010 at 14:11

2 Answers 2

0

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.

0

I think it is the calling convention issue.

Please try the following code:

class gph 
{
public:

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

};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.