0

I have created a dll where I have declared some functions that accept struct as parameters along with source where I have these functions defined.

The library compiles without any issues but when I link it with my sample client program I get linker error 2019 for the functions and struct declared and defined in my library. Any advice would be much appreciated.

For declaring the structure so that it is available in the source file as well as the linking test app, I did as explained in the below link (one of the very few threads on the internet that answers how one should include struct in a DLL) Making a structure visible in both library and application - C

I have got the struct declared in a header file and included the header file in my library header file that has the declarations for my functions. I have a sample file with the same name which has both the structure header and the library header file included.

Unfortunately for me, I am still getting lnk2019 for the functions and the struct I have declared in my library.

My Library header:

#include "STRUCTURE.h"
#include "debug.h"
#ifdef LINKEDLISTDLL_EXPORTS
#define LINKEDLISTDLL_API __declspec(dllexport) 
#else
#define LINKEDLISTDLL_API __declspec(dllimport) 
#endif

LINKEDLISTDLL_API pEntry initialize(pEntry);
LINKEDLISTDLL_API pEntry InsertatHead(pEntry, pEntry);
LINKEDLISTDLL_API pEntry InsertatTail(pEntry, pEntry);
LINKEDLISTDLL_API pEntry RemoveatHead(pEntry);
LINKEDLISTDLL_API pEntry RemoveatTail(pEntry);

STRUCTURE.h:

#ifndef STRUCTURE_H 
#define STRUCTURE_H   

typedef struct List_Entry
{
    struct List_Entry* FLink;
    struct List_Entry* BLink;
}Entry, * pEntry;

#endif

pch.h:

#ifndef PCH_H
#define PCH_H

// add headers that you want to pre-compile here
#include "framework.h"
#include "STRUCTURE.h"
#include "debug.h"
#include "LINKEDLISTDLL.h"

#endif //PCH_H

Any advice on what I might be doing wrong here? My sample code has all these headers included and the lib file linked. The lib file builds without any issues. Any help will be much appreciated. Please let me know if any more details are required. Thanks in advance.

Ngage
  • 1
  • 1
  • Did you forgot to add `#define LINKEDLISTDLL_EXPORTS` in the DLL main file and **not** in the test app main file? – fpiette Jun 24 '21 at 19:24
  • @fpiette so do I just need to add '#define LINKEDLISTDLL_EXPORTS' in the default DLL Main? By DLL main do you mean my source file that contains all the function definitions? Or do you mean the default file that gets generated with the DLL template in vs2019? I created my project using the DLL template in VS2019 and followed this https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=msvc-160 Do I still need to add to DLL Main? I did it anyway but with no success. – Ngage Jun 25 '21 at 06:09
  • I think it did the trick. The problem was that earlier I had set the type config type to static while troubleshooting but as soon as I switched it back to DLL after adding #define LINKEDLISTDLL_EXPORTS. It generated a lib and DLL file, which it was not doing earlier - it was either setting it to DLL only (when config type was DLL) or Lib only (when setting static). Thanks so much for the help. I think that was the answer to my problem. I don't know how to mark a comment as an answer but if you could put it as an answer, I will mark it. – Ngage Jun 25 '21 at 08:15

0 Answers0