1

I followed step by step how to include a dll project in a Visual Studio solution in this link When I did the test to check if the dll function is well linked to the application, it recognises it. But? I am having now an error which looks like what is follow:

PS: init_test() is a Dll function APP is the application and in one of its function (image(void)), I included DLL:init_test()

Error   4   error LNK2019: unresolved external symbol "public: static void __cdecl DLL::init_test(unsigned long)" (?init_test@DLL@@SAXK@Z) referenced in function "public: void __thiscall APP::image(void)" (?image@APP@@QAEXXZ)   C:\Users\xxx\apps\APP\APP.obj
Error   5   error LNK1120: 1 unresolved externals   C:\Users\xxx\APP.exe

Let me try to represent what I did:

#ifdef DLL_EXPORTS
#define DLL_API __declspec(dllexport) 
#else
#define DLL_API __declspec(dllimport) 
#endif

class DLL
{
public:
static void image_test();
};


void APP:image()
{
....
....
DLL::image_test();
}
MelMed
  • 1,702
  • 5
  • 17
  • 25
  • You need to provide more info for some one to find the problem for you i.e. showing what you exactly did. The error still simply means your main was not able to find the function's definition at link time – fkl Oct 03 '13 at 07:24
  • http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – stijn Oct 03 '13 at 07:25
  • @fayyazkl please see my edit. It should be more clear now. – MelMed Oct 03 '13 at 07:35
  • I was going to write a pointless diatribe on how to do this, but instead [Just read this](http://msdn.microsoft.com/en-us/library/a90k134d.aspx). – WhozCraig Oct 03 '13 at 07:55
  • @WhozCraig the link I have already dealt with it! – MelMed Oct 03 '13 at 08:02
  • @MelMed But you haven't done what was pointed out in the various links. I'm no expert on this at all but `class DLL_API DLL`, see here http://msdn.microsoft.com/en-us/library/8fskxacy.aspx for instance. – john Oct 03 '13 at 08:37
  • I have to tell you that my application is a Qt one by the way. Does that apply to it as well? – MelMed Oct 03 '13 at 11:30
  • Yes you should use the DLL_API even if you are using Qt. – drescherjm Oct 03 '13 at 16:21

1 Answers1

1

Change

class DLL
{
public:
static void image_test();
};

to

class DLL_API  DLL
{
public:
static void image_test();
};

so that image_test() will be exported and you will get an import lib in addition to your dll. This should help solve some of your other questions on the same topic.

Also remember for this to work DLL_EXPORTS must be defined in your .dll only so add it to your C/C++/Preprocessor/Preprocessor Definitions for your dll in all configurations ( debug, release, RelWithDebInfo ...)

drescherjm
  • 10,365
  • 5
  • 44
  • 64