I found this issue (see the title of my question) many times on the internet and at stackoverflow although most often related to objects. No objects here. Just plain C/C++. I tried most of the suggestions to solve it. Nothing worked. The code below has been reduced to the minimum to isolate the problem. It's Visual Studio 2013, C++. I want to use a DLL with functions written in C. Below, the .h file called Strings_LV_CPP.h.
#pragma pack(1)
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
LStrHandle s;
} TStruct_String;
/*!
* Write_Struct_String
*/
void __cdecl Write_Struct_String(char StringI[], TStruct_String *StructI,
TStruct_String *StructO);
#ifdef __cplusplus
} // extern "C"
#endif
#pragma pack(pop)
followed by the main program.
#include <windows.h>
#include <Strings_LV_CPP.h>
int main()
{
char s[] = "STRING";
TStruct_String *CL;
CL = (TStruct_String *)malloc(sizeof(TStruct_String));
// void __cdecl Write_Struct_String(char StringI[], TStruct_String *StructI, TStruct_String *StructO)
Write_Struct_String(s, CL, CL);
return 0;
}
The output produced by Build is:
1>------ Rebuild All started: Project: LVStructString, Configuration: Debug Win32 ------
1>LVStringApplication.cpp
1>LVStringApplication.obj : error LNK2019: unresolved external symbol _Write_Struct_String referenced in function _main
1>C:\Users\Werf\Documents\Local CPP projects\LVStructString\Debug\LVStructString.exe : fatal error LNK1120: 1 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Visual Studio: Used a clean installation of Visual Studio, created a fresh blank project, console and win32, but no difference. Tried many different options and combinations as suggested but seemed to have missed the right one. No result, so decided to consult my colleagues of the world.
Most obliged with any answer.
Dirk