Error LNK2019: unresolved external symbol

本文介绍了解决C++项目中出现的LNK2019未解析外部符号错误的方法。通常此错误发生在使用C风格导出库时。通过在包含头文件时声明extern C可以避免名称修饰问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值