Name DecorationNormally this refers to C++ naming conventions, but it applies to a number of non-C++ cases as well. C++ by default will use the name of a function, its parameters and its return type when calculating a name for a function. The linker function name for void CALLTYPE test(void)might come to anything in the table below depending on what CALLTYPE is and what language you are using. CALLTYPEs such as __cdecl, __fastcall, and __stdcall can change the naming conventions for a function/variable. Calling convention | extern “C” or .C file | .CPP , .CXX or /TP ----------------------------------------------------------------------------- C naming convention | _test | ?test@@ZAXXZ (__cdecl) | | ----------------------------------------------------------------------------- Fastcall naming convention | @test@0 | ?test@@YIXXZ (__fastcall) | | ----------------------------------------------------------------------------- Standard Call naming | _test@0 | ?test@@YGXXZ convention (__stdcall) | |Use extern “C” when calling a C function from a C++ program. Extern “C” forces use of the C naming convention for non-class C++ functions. Be aware of compiler switches like /TP or /Tc that force a file to be compiled as a C (/Tc) or C++ (/TP) file no matter what the filename extension, or you may get different function names than you expect.Having function prototypes that have mismatched parameters can also cause this error. Name decoration incorporates the parameters of a function into the final decorated function name. Calling a function with the parameter types that do not match those in the function declaration may also cause LNK2001. There is currently no standard for C++ naming between compiler vendors or even between different versions of a compiler. Therefore linking object files compiled with other compilers may not produce the same naming scheme and thus causes unresolved externals.
Calling convention | extern “C” or .C file | .CPP , .CXX or /TP
-----------------------------------------------------------------------------
C naming convention | _test | ?test@@ZAXXZ
(__cdecl) | |
-----------------------------------------------------------------------------
Fastcall naming convention | @test@0 | ?test@@YIXXZ
(__fastcall) | |
-----------------------------------------------------------------------------
Standard Call naming | _test@0 | ?test@@YGXXZ
convention (__stdcall) | |Use extern “C” when calling a C function from a C++ program. Extern “C” forces use of the C naming convention for non-class C++ functions. Be aware of compiler switches like /TP or /Tc that force a file to be compiled as a C (/Tc) or C++ (/TP) file no matter what the filename extension, or you may get different function names than you expect.Having function prototypes that have mismatched parameters can also cause this error. Name decoration incorporates the parameters of a function into the final decorated function name. Calling a function with the parameter types that do not match those in the function declaration may also cause LNK2001. There is currently no standard for C++ naming between compiler vendors or even between different versions of a compiler. Therefore linking object files compiled with other compilers may not produce the same naming scheme and thus causes unresolved externals.
方法:你把*.lib文件,拷入你的工作目录下,或者,你把他拷入System32目录下OR
project-->Setings-->Link-->Object/library moudles 中加入你做的动态库的*.lib文件。
#ifdef __cplusplus
extern "C" {
#endif
int __declspec(dllimport) fn(int i);
#ifdef __cplusplus
}
#endif