Error LNK2019: unresolved external symbol (from device team)

Error LNK2019: unresolved external symbol


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 <windbase_edb.h>
}

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

错误 `LNK2001: unresolved external symbol` 是 Microsoft Visual C++ 编译器中常见的链接器错误,通常表示链接器在最终链接阶段无法找到某个函数或变量的定义。以下是解决该问题的几种方法: ### 1. 检查函数或变量的定义 确保所有声明的函数或全局变量都有对应的定义。例如,如果在头文件中声明了一个函数: ```cpp // myheader.h void myFunction(); ``` 那么在对应的 `.cpp` 文件中必须提供其实现: ```cpp // mysource.cpp #include "myheader.h" void myFunction() { // 函数实现 } ``` 如果缺少实现,链接器将无法解析该符号[^1]。 ### 2. 检查项目配置 如果项目包含多个文件,确保所有 `.cpp` 文件都已正确添加到项目中,并参与编译。有时候文件可能未被加入到构建流程中,导致链接器找不到其定义[^2]。 ### 3. 处理 C 与 C++ 混合编译的问题 如果在 C++ 文件中调用 C 函数,需要使用 `extern "C"` 来防止名称修饰(name mangling)问题。例如: ```cpp // 在 C++ 文件中声明 C 函数 extern "C" { void cFunction(); } ``` 同时确保 `.c` 文件的函数定义没有被 C++ 编译器错误地修饰[^4]。 ### 4. 检查 Windows 子系统设置 对于 Windows 应用程序,如果提示 `unresolved external symbol _WinMain@16`,则可能是项目设置错误。可以通过以下方式调整: - 打开项目属性页(右键项目 -> 属性)。 - 进入 **配置属性 -> C/C++ -> 预处理器**,检查是否定义了 `WIN32`。 - 进入 **配置属性 -> 链接器 -> 系统**,设置 **子系统** 为 `Windows (/SUBSYSTEM:WINDOWS)`[^3]。 ### 5. 检查库文件的链接 如果使用了外部库,确保在 **项目属性 -> 配置属性 -> 链接器 -> 输入** 中添加了相应的 `.lib` 文件。此外,确认库文件路径是否已正确配置在 **VC++ 目录 -> 库目录** 中[^5]。 ### 6. 检查类成员函数的实现 如果使用 MFC 或其他类库,确保派生类正确重写了基类的虚函数。例如: ```cpp class CMyPage : public CPropertyPage { public: virtual BOOL OnSetActive(); }; ``` 在 `.cpp` 文件中必须提供 `OnSetActive` 的实现: ```cpp BOOL CMyPage::OnSetActive() { // 自定义逻辑 return CPropertyPage::OnSetActive(); } ``` 否则链接器会报错[^5]。 ### 7. 清理并重新生成项目 有时候旧的编译残留可能导致链接问题,尝试执行 **清理解决方案** 并重新编译整个项目。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值