zoukankan      html  css  js  c++  java
  • VS2010编译错误 LNK 2019 unresolved external symbol错误解决办法

    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 "....	hird-partplustachecontext.hpp"
       4: #include "....	hird-partjsoncppjson.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 "....	hird-partplustachecontext.hpp"
      26: #include "....	hird-partjsoncppjson.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: };

  • 相关阅读:
    Kubernetes学习之路(十)之资源清单定义
    Kubernetes学习之路(十一)之Pod状态和生命周期管理
    Kubernetes学习之路(七)之Coredns和Dashboard二进制部署
    Kubernetes学习之路(九)之kubernetes命令式快速创建应用
    Kubernetes学习之路(八)之Kubeadm部署集群
    Ceph学习之路(三)Ceph luminous版本部署
    Kubernetes学习之路(六)之创建K8S应用
    Redis学习之路(二)之Redis入门基础
    Redis学习之路(一)之缓存知识体系
    OpenStack入门篇(二十二)之实现阿里云VPC的SDN网络
  • 原文地址:https://www.cnblogs.com/mforestlaw/p/3289368.html
Copyright © 2011-2022 走看看