简体   繁体   中英

Unresolved external symbols in C++

I have three functions defined in a C++ Dll program developed under VS2010.

int __stdcall Scan()
{
...
}

int __stdcall Setup(int e_time, double s_value, double cs_value, double gain, int nIm, char* name) 
{
...
}

int __stdcall TearDown()
{
....
}

I defined them in Program.def as

LIBRARY
EXPORTS
   Scan @1
   Setup @2
   TearDown @3

I also have a headefile Program.h

//DLL Export-Import definitions
#define BUILD_DLL

#ifdef BUILD_DLL
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __declspec(dllimport)
#endif

But I am getting some errors:

  • "49 error LNK2001: unresolved external symbol Scan in Program.def line 1"
  • "51 error LNK2001: unresolved external symbol Setup in Program.def line 1"

and

  • "51 error LNK1120: 2 unresolved externals symbol in Program.lib"

Error message does not complain about the third function defined. I used /MAP option in the linker, and defined a file name for the map file, but I am not getting a MAP file output to check how these sysmbols are defined. I cannot use dumpbin program since build did not create a dll file yet.

I am stuck. Any help/pointers will be greatly appreciated. Thanks.

You need to declare C-style linkage or the C++ name decoration messes things up.

Use, for each function

extern "C" {
    /*your function here*/
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM