• 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: };

  • 相关阅读:
    开通了
    A computer hardware platform abstraction
    脑机接口入门概览
    JDK自带VM分析工具jps,jstat,jmap,jconsole
    泛型里的super和extend
    动态规划
    用二分法查找的套路(一)
    A computer hardware platform abstraction
    CentOS7安装JDK1.8
    CentOS7如何修改hostname
  • 原文地址:https://www.cnblogs.com/mforestlaw/p/3289368.html
Copyright © 2020-2023  润新知