c++ - Unresolved external symbol Visual Studio 2010 错误

标签 c++ unresolved-external

我已经使用 visual studio 2010 professional 实现了一个包含 2 个项目的解决方案;第一个称为 OptDll 由一个动态库和我要导出的方法组成,而第二个是一个名为 prova 的 exe 项目,以便尝试 dll。 在我决定在 OptDll 项目中插入一个新类 (GlobalOutput) 以创建我想要的输出参数之前,我已经包含了正确的引用并且一切正常。当我构建项目 OptDll 时没有发生错误,但是当我构建整个解决方案时,我在 prova 项目中遇到了这些错误:

Error   59  error LNK2019: unresolved external symbol "public: __thiscall GlobalOutput::~GlobalOutput(void)" (??1GlobalOutput@@QAE@XZ) referenced in function _main C:\Users\ANTONIO\Desktop\optDll\prova\prova.obj

Error   60  error LNK2019: unresolved external symbol "public: __thiscall GlobalOutput::GlobalOutput(void)" (??0GlobalOutput@@QAE@XZ) referenced in function _main  C:\Users\ANTONIO\Desktop\optDll\prova\prova.obj

Error   61  error LNK1120: 2 unresolved externals   C:\Users\ANTONIO\Desktop\optDll\Debug\prova.exe 1

我读到它可能是类构造函数/析构函数的问题,但我没有修复它。 在感兴趣的代码下方。

OptFunDll.h
#ifdef OPTFUNDLL_EXPORTS
#define OPTFUNDLL_API __declspec(dllexport) 
#else
#define OPTFUNDLL_API __declspec(dllimport) 
#endif

//#include "tool_library.h"
#include "GlobalOutput.h"

namespace optFun
{
    // This class is exported from the optFunDll.dll
    class myoptFun
    {
    public: 
        // funzione che implementa il modulo di ottimizzazione
        class OPTFUNDLL_API GlobalOutput;
        static OPTFUNDLL_API void scheduling(const char*,const char*,const char*,const char*,GlobalOutput&); 


    };
}

OptFunDll.cpp
#include "stdafx.h"
#include "optFunDll.h"
#include <stdexcept>

using namespace std;

::Random Particle::_rnd;
::Random ParticleSwarm::_rnd;

namespace optFun
{
    void myoptFun::scheduling(const char *pRicette,const char *pWarehouse,const char *pFarmacia,const char *pShaker,GlobalOutput& total){
//here some code...
//class definition
total.CreateDataPrescription(final_list);
total.time=time_output;

GlobalOutput.h
#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#include <afxadv.h>
#include <afxdisp.h>        // MFC Automation classes
#include <afxdtctl.h>        // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>            // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include "GlobalInfo.h"
#include "tool_library.h"

struct DataPrescription{
    EDrug  NameDrug;
    double Dosage;
    EContainerType DestType;
    ELiquid IdDest;
    double CapacityDest;
    double Priority;
    bool ScaricoShaker;

    DataPrescription(){
        NameDrug=EDrug_NoDrug;
        Dosage=0.0;
        DestType= EContainerType_Tot;
        IdDest=ELiquid_NoLiquid;
        CapacityDest=0.0;
        Priority=0.0;
        ScaricoShaker=true;
    }

    DataPrescription(EDrug name,double dos,EContainerType dest,ELiquid ID,double cap_dest,double p,bool _ScaricoShaker){
        NameDrug=name;
        Dosage=dos;
        DestType=dest;
        IdDest=ID;
        CapacityDest=cap_dest;
        Priority=p;
        ScaricoShaker=_ScaricoShaker;
    }
};

class GlobalOutput{
public:
    CArray<DataPrescription> OptList;
    time_info time;

    GlobalOutput();
    ~GlobalOutput();

    void CreateDataPrescription(vector<ricetta>&);
};


#endif

GlobalOutput.cpp
#include "stdafx.h"
#include "GlobalOutput.h"

GlobalOutput::GlobalOutput(){
    time.total_makespan=0;
}

GlobalOutput::~GlobalOutput(){
}

void GlobalOutput::CreateDataPrescription(vector<ricetta>& list){

    //DataPrescription tmp;

    for(unsigned int i=0;i<list.size();i++){
        DataPrescription tmp(list[i].getID(),list[i].getdosage(),list[i].get_destination(),list[i].get_DestType(),list[i].get_CapacityDest(),list[i].getPriority(),list[i].processing_info.scarico_shaker);
        this->OptList.Add(tmp);
    }
}

最后是 prova 项目的主要部分:

#include "stdafx.h"
#include "optFunDll.h"
#include <iostream>
//#include "C:\Users\ANTONIO\Desktop\optDll\optDll\tool_library.h"

using namespace std;


int main()
{
    const char *pRicette;
    pRicette=new char(NULL);
    const char *pWarehouse;
    pWarehouse=new char(NULL);
    const char *pFarmacia;
    pFarmacia=new char(NULL);
    const char *pShaker;
    pShaker=new char(NULL);
    optFun::myoptFun::GlobalOutput  total;
    optFun::myoptFun::scheduling(pRicette,pWarehouse,pFarmacia,pShaker,total);

    return 0;
}

感谢您的帮助。 如果您需要更多信息,请告诉我。

如果我在 OptDll.cpp 中的类定义下注释代码行,我会收到以下错误: 错误 5 error C2079: 'total' 使用未定义的类 'optFun::myoptFun::GlobalOutput' c:\users\antonio\desktop\optdll\prova\prova.cpp 23

Error   6   error C2664: 'optFun::myoptFun::scheduling' : cannot convert parameter 5 from 'int' to 'optFun::myoptFun::GlobalOutput &'   c:\users\antonio\desktop\optdll\prova\prova.cpp 24

相反,如果我取消注释 total 的定义,我也会得到: 9 IntelliSense: 不完整的类型是不允许的 c:\users\antonio\desktop\optdll\optdll\optfundll.cpp 131

感谢您的参与,我是 C++ 编程的新手。

最佳答案

您实际上并没有导出类 GlobalOutput

你需要:

class OPTFUNDLL_API GlobalOutput

关于c++ - Unresolved external symbol Visual Studio 2010 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22247615/

相关文章:

c++ - C++ 中的 Iterator 不是一种指针吗?

c++ - 什么是 undefined reference /未解析的外部符号错误以及如何修复它?

c++ - DLIB On visual studio 2015 抛出 Unresolved external 错误

c++ - 在 Windows 上构建 PoDoFo - Unresolved external 问题

c++ - 从 boost::packaged_task 生成的 future 会抛出错误的异常吗?

c++ - 可变参数宏是非标准的吗?

c++ - 模板类的模板友元函数

c++ - __purecall 在 VS2010 中使用虚函数的问题 - 一旦方法获得 purecall

c++ - protocol buffers + zlib = 未解析的外部符号

c++ - 什么是 undefined reference / Unresolved external symbol 错误,我该如何解决?