VS2010编译错误 LNK 2019 unresolved external symbol错误解决办法

本文详细介绍了在C++项目中引用DLL函数时遇到的LNK2019连接错误,通过修改DLL函数导出配置成功解决问题。包括具体代码修改步骤及原理解释。

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

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:  
   3: #include "..\..\third-part\plustache\context.hpp"
   4: #include "..\..\third-part\jsoncpp\json.h"
   5:  
   6: class DataConversion {
   7: public:
   8:     DataConversion();
   9:     ~DataConversion();
  10:     static Context JsonToContext(char *printData);
  11: private:
  12:     static PlustacheTypes::ObjectType ConvertObject(const Json::Value& json, Context* ctx);
  13:     static PlustacheTypes::CollectionType ConvertCollection(const Json::Value& json);
  14:     static void ConvertPrimative(const Json::Value& json, CString& value);
  15: }; 
  16: //上面代码是一个dll中的头文件,需要在其他工程中使用 Context JsonToContext(char *printData);这个函数,怎么调用都是连接错误,后来想到是dll函数导出的问题,于是修改成如下代码即可
  17: #pragma once
  18:  
  19: #ifdef PRINTERPLUGIN_EXPORTS
  20: #define PRINTERPLUGIN_API __declspec(dllexport)
  21: #else
  22: #define PRINTERPLUGIN_API __declspec(dllimport)
  23: #endif
  24:  
  25: #include "..\..\third-part\plustache\context.hpp"
  26: #include "..\..\third-part\jsoncpp\json.h"
  27:  
  28: class DataConversion {
  29: public:
  30:     DataConversion();
  31:     ~DataConversion();
  32:     PRINTERPLUGIN_API static Context JsonToContext(char *printData);
  33: private:
  34:     static PlustacheTypes::ObjectType ConvertObject(const Json::Value& json, Context* ctx);
  35:     static PlustacheTypes::CollectionType ConvertCollection(const Json::Value& json);
  36:     static void ConvertPrimative(const Json::Value& json, CString& value);
  37: };

转载于:https://www.cnblogs.com/mforestlaw/p/3289368.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值