尝试测试dll时出现LNK2019错误
LNK2019 error when trying to test a dll
我使用一个应用程序(几周前才开始,所以我还在学习旧的应用程序)用C语言构建,我的公司希望使用该程序的能力来调用外部DLL来扩展一些新功能。为此,我开始编写POC,即下面的前两个文件。我们得到的唯一规范是dll必须导出以下函数:extern int __stdcall TestMethod_LoadCustomer(const char * name, char * id);
我试着这样实现:
TestDLL.h
#define TestDLL_API __declspec(dllexport)
namespace TestDLL
{
class TestDLL
{
public:
static TestDLL_API int TestMethod_LoadCustomer(const char* name, char* id);
};
}
TestDLL.cpp
// TestDLL.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "TestDLL.h"
#include <string.h>
extern "C" int __declspec(dllexport) __stdcall TestMethod_LoadCustomer(const char* name, char* id)
{
if (strlen(name) <= 8) {
strcpy(id, name); // name contains customer id
} else {
id[0] = 0; // Customer not found
}
return 0;
}
这两个文件编译得很好。当我试图通过一个单独的小控制台应用程序测试这个dll时,问题出现了:RunTEST.cpp
// RunTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include "TestDLL.h"
using namespace std;
int _tmain()
{
char* id= "";
TestDLL::TestDLL::TestMethod_LoadCustomer("77777", id);
cout << id;
cin >> id;
return 0;
}
所有我正在寻找的是能够在一个字符串传入调用TestMethod_LoadCustomer(),并有它被添加到id字段。
当我实际尝试构建此解决方案时,我得到以下错误:
"error LNK2019: unresolved external symbol "public: static int __cdecl TestDLL::TestDLL::TestMethod_LoadCustomer(char const *, char *)"(?TestMethod_LoadCustomer@TestDLL@1@SAHPBDAD@ z)引用函数_wmain"
我假设它与我试图在客户端应用程序中引用它的方式有关,但我不确定。我看过StackOverflow上的其他LNK2019错误,但这些解决方案似乎都不起作用,因为我错误地实现了它们。有谁能帮我去掉这个错误信息吗?
关于TestDLL.cpp文件缺少两件事:
1)命名空间TestDLL.
2) TestDLL::在方法名之前。
// TestDLL.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "TestDLL.h"
#include <string.h>
namespace TestDLL {
extern "C" int __declspec(dllexport) __stdcall TestDLL::TestMethod_LoadCustomer(const char* name, char* id)
{
if (strlen(name) <= 8) {
strcpy(id, name); // name contains customer id
} else {
id[0] = 0; // Customer not found
}
return 0;
}
}
在TestDLL.cpp中定义函数时,您没有提到该函数是类TestDLL的成员。
- 链接CPP文件进行测试时发生LNK2019错误
- 32位到64位:LNK2019错误,如何检索相关信息
- 在结构函数之间传递文件路径 C++ 编辑:修复LNK2019错误
- 尝试使用 TMXlite 编译项目时LNK2019错误
- LNK2019错误;此处缺少/未定义的内容
- DX11 DirectInput8创建引起LNK2019错误
- C++ mysql 仅在构建解决方案时LNK2019错误
- C LNK2019错误,未解决的外部字符
- C++ 带有出现LNK2019错误的对象的链接列表
- 解决 main 中的LNK2019错误
- 尝试使用命名空间中的函数时LNK2019错误
- LNK2019错误未解析的外部符号
- LNK2019错误,在Visual Studio 2012 C++的main中使用的函数
- 同一项目中两个类之间的visual c++LNK2019错误
- LNK2019错误(未解析的外部符号)将SQLite链接到DLL
- C++/CLI 包装器LNK2028和LNK2019错误
- LNK2019错误,尝试覆盖运算符<< 对于 LinkedList 类
- LNK2001和LNK2019错误 - DirectX 未解析的外部符号
- (2012)Visual C++LNK2019错误,可能是模板问题
- LNK2019错误一个DLL链接到MFC DLL