大智若愚  
拈花一笑,淡然处之……
日历
<2010年11月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

留言簿

随笔档案(18)

文章分类

最新随笔

最新评论

 
最近写的程序一个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.

版权声明:以上内容皆摘自网上,仅供参考学习!
posted on 2010-11-19 13:25 灭神佛 阅读(16668) 评论(1)  编辑 收藏 引用
评论:
  • # re: Error LNK2019: unresolved external symbol [未登录]  lily Posted @ 2013-12-17 18:07
    学习了  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


 
Copyright © 灭神佛 Powered by: 博客园 模板提供:沪江博客