您的位置:首页 > 其它

Error LNK2019: unresolved external symbol

2012-05-20 20:38 411 查看
最近写的程序一个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.

版权声明:以上内容皆摘自网上,仅供参考学习!

转自:http://www.cppblog.com/Dutyboy/archive/2010/11/19/134082.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐