最近写的程序一个solution里有两个projects,一个c++的project要调用c project,编译的时候一直出现link error,Error LNK2019: unresolved external symbol。查了好长时间才发现下面的解决方法,很不错。
http://blogs.msdn.com/vsdteam/archive/2005/11/20/495123.aspx
Error LNK2019: unresolved external symbol int __cdecl CeMountDBVolEx, void * __cdecl CeOpenDatabaseInSession
You have created a C++ device project and using the EDB methods from “coredll.lib”. You have included the “windbase_edb.h” file in your projects source files. When you compile and link this you are getting following linker errors
error LNK2019: unresolved external symbol “int __cdecl CeMountDBVolEx(struct _CEGUID *,wchar_t *,struct _CEVOLUMEOPTIONS *,unsigned long)” (?CeMountDBVolEx@@YAHPAU_CEGUID@@PA_WPAU_CEVOLUMEOPTIONS@@K@Z) referenced in function “int __cdecl MountDbVol(void)” (?MountDbVol@@YAHXZ)
error LNK2019: unresolved external symbol “void * __cdecl CeOpenDatabaseInSession(void *,struct _CEGUID *,unsigned long *,wchar_t *,struct _SORTORDERSPECEX *,unsigned long,struct _CENOTIFYREQUEST *)” (?CeOpenDatabaseInSession@@YAPAXPAXPAU_CEGUID@@PAKPA_WPAU_SORTORDERSPECEX@@KPAU_CENOTIFYREQUEST@@@Z)
and you are wondering why this is happening?
The problem with your project is that you are using a “C” style exported library in your C++ projects. When the compiler generates mangled names for C++ functions, they are different from unmangled names generated by the C compiler and hence the C++ compiler will not be able to link with the methods imported from coredll.lib.
The solution to this problem is – while including the header windbase_edb.h, you can explicitly tell the compiler that all functions included from this header are “C” style functions by changing your inclusion as below.
extern “C”
{
#include
}
With this the C++ compiler when includes the declarations from the windbase_edb.h file, it does not do any name mangling for the functions declared in this file, and thus you should be able to link to EDB without any problems now.
Gangadhar Heralgi
Published Sunday, November 20, 2005 8:17 PM by vsdteam