【问题标题】:error LNK2019: unresolved external symbol CheckLr referenced in function错误 LNK2019:函数中引用了未解析的外部符号 CheckLr
【发布时间】:2016-08-17 10:14:11
【问题描述】:

legitmate_relationship.dll :基本上这个 dll 用于单元测试项目 unittest_legitimate_relationship 之一。

一旦我构建了 unittest_legitimate 项目,就会出现一些链接器错误。


错误 LNK2019:函数“private: bool __cdecl LrTester::LrTest()

中引用了无法解析的外部符号 CheckLr

这是我将在我的单元测试项目中调用的函数defalcation,它在“legitmate_relationship.h”头文件中声明

#ifdef __cplusplus
extern "C"
{
#endif

DLL_IMPORT (bool_t)
CheckLr(STD_HANDLE hPrincipal, STD_HANDLE hCollectionIn, STD_HANDLE hCollectionOut);

#ifdef __cplusplus
}

函数在文件“lrrule.cpp”中是这样定义的

DLL_EXPORT (bool_t)
CheckLr(STD_HANDLE hCollectionIn, STD_HANDLE hCollectionOut, STD_HANDLE hPrincipal)
{   

}  

为了在 unittest_legitimate 项目中使用 checklr 功能,我在附加依赖项中添加了 .lib 文件引用。这样函数定义应该可用于项目。

如果我正在编译 unittest-legitimate 项目,我会收到上面提到的链接器错误。

在 lrtest.cpp 中调用 checklr():

CheckLr((STD_HANDLE)permissionCollectionIn, (STD_HANDLE)permissionCollectionOut, (STD_HANDLE)principal);

我不确定如何解决此类链接器错误。提前致谢。

【问题讨论】:

  • lrtest.cpp 和 legitmate_relationship.h 和 lrrule.cpp 是否在同一个对象中?
  • legitmate_relationship.h 和 lrrule.cpp 在 legalrelasionship.dll 文件中。头文件有导入声明,源文件有导出定义。
  • lrtest.cpp 是 unittest_legitimate-relationship.exe 项目文件的一部分。在这个文件中,我正在调用导出的定义。

标签: c++ visual-c++ dll linker


【解决方案1】:

1.检查三件事,legalrelasionship.dll项目和unittest_legitimate-relationship.exe项目应该是一样的:

MT/MD

x86/x64

cplusplus/c

2.legalrelasionship.dll 项目生成一个legalrelasionship.lib 文件。 unittest_legitimate-relationship.exe 项目应该链接到这个 legalrelasionship.lib 文件。

【讨论】:

  • X64 运行和运行时库属性均设置为 /MDd
  • 你有这个函数“private: bool LrTester::LrTest()”吗?
  • LrTest的body是否在cpp文件中,cpp文件编译链接到?
  • 我不确定,如何检查该步骤。
  • 首先,LrTest() 在哪里?在 .h 文件中,还是在 .cpp 文件中?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-06
  • 2013-12-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多