Link错误有很多种,主要是没有在连接中加入lib文件路径,或者lib配置正确,传参错误
一个solution里面多个project之间引用其他project函数会出现这个错误,由于包含了头文件而没处理lib文件导致,解决办法有如下几种:
1.在引用外部函数的cpp文件的头文件包含列表下添加 #pragma comment(lib, "xxx.lib")
2.在引用其他动态库的工程的Properties->Configuration Properties->Linker->Additional Dependencies中添加lib文件路径
3.在引用其他动态库的工程的Properties->Common Properties->Framework and References中Add New Reference选择依赖的工程
最近遇到一个问题,lib配置正确,传参也没问题,仍报LNK2019。。。。找了许久发现是引用dll中的函数而没有使用dll函数导出配置代码如下
1: #pragma once
2:
5:
class DataConversion {
public:
8: DataConversion();
9: ~DataConversion();
char *printData);
private:
const Json::Value& json, Context* ctx);
const Json::Value& json);
const Json::Value& json, CString& value);
15: };
//上面代码是一个dll中的头文件,需要在其他工程中使用 Context JsonToContext(char *printData);这个函数,怎么调用都是连接错误,后来想到是dll函数导出的问题,于是修改成如下代码即可
17: #pragma once
18:
19: #ifdef PRINTERPLUGIN_EXPORTS
20: #define PRINTERPLUGIN_API __declspec(dllexport)
else
22: #define PRINTERPLUGIN_API __declspec(dllimport)
23: #endif
24:
27:
class DataConversion {
public:
30: DataConversion();
31: ~DataConversion();
char *printData);
private:
const Json::Value& json, Context* ctx);
const Json::Value& json);
const Json::Value& json, CString& value);
37: };