1

I've spent the last 2 days searching for and implementing the answers from similar questions into my code with little success. I have an API that is an external .dll (windows) and I have the header file included into my .cpp file to reference the API.

However I have this issue that no matter what I do, I always get an unresolved external symbol that references this line in my .h file. Yes, I have used Google and modified the answers I found into my code, with no success.

Foo.h

Class Foo {
    public:
        static Foo* Interface_Get(char* dllfilename);

Foo.cpp

// I declare this just underneath the #include "Foo.h" header
Foo *foo = 0;

Inside my main function I declare it as this (along with some other functions that are fine).

//This has already been created and both Header and .dll are in the same directory.
Foo::Interface_Get("bar.dll"); 

And I get this error

error LNK2019: unresolved external symbol 
    "public: static class Foo * __cdecl Foo::Interface_Get(char *)"

I've tried everything I know (This is my first .dll creation experience) I have a feeling I am missing something painfully obvious, but for the life of me I cannot see it.

Entire Foo.cpp

#include "Foo.h"
Foo* Foo::Interface_Get(char* dllfilename); //May not be redeclared outside class error

Foo* foo = 0;

bool Frame()
{
if (foo->Key_Down(DIK_ESCAPE))
    return false;   
return true;
}


INT WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
{
foo->Interface_Get("bar.dll");

foo->System_SetState(grSTATE_FRAME, Frame);

foo->System_SetState(grSTATE_WINDOWED, true);

foo->System_SetState(grSTATE_KEYBOARD, true);

foo->System_Initiate();

foo->System_Start();

foo->System_Shutdown();

foo->Inferface_Release();

return 0;
}
user1945128
  • 13
  • 1
  • 4

2 Answers2

3

This question explains common problems, and in your case it's (probably) a combination of:

  • (possibly) forgetting to implement the function
  • forgetting __declspec(dllexport)
  • forgetting to link against the library
Community
  • 1
  • 1
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
1

You need to provide function definition for Interface_Get(char* dllfilename); if you haven't done that.

This only redeclares function again, you need to provide function like below format with {}

Foo* Foo::Interface_Get(char* dllfilename); //May not be redeclared outside class error

Foo.cpp

Foo* Foo::Interface_Get(char* dllfilename)
{
  //....
  return new Foo();
}
billz
  • 44,644
  • 9
  • 83
  • 100
  • Angew - The Foo::Interface_Get is defined already in the dll. I am also linking it to a header that contains definitions of all functions. Karthik - This is so I can do this foo->Interface_Get(...); Instead of Foo::Interface_Get(...); – user1945128 Jan 03 '13 at 09:49
  • billz - Already tried that in my .cpp file. I get 'may not be redeclared outside it's class'. I've tried doing it in the header also but within the class, still doesn't work. – user1945128 Jan 03 '13 at 09:51
  • see my updated answer, you need to provide function definition which you haven't – billz Jan 03 '13 at 09:58
  • billz - I have done that in an included .cpp file that is part of the compiled .dll, I was hoping it would find that definition and then allow me to define a new function with my arguments in INT WINAPI.... – user1945128 Jan 03 '13 at 10:16
  • then it could be the issue as Luchian mentioned. – billz Jan 03 '13 at 10:17