C++ 未解析的外部符号visual studio 2010错误
我已经用VisualStudio2010 professional实现了一个包含2个项目的解决方案;第一个名为OptDll的程序由一个动态库组成,其中包含一个我想要导出的方法,而第二个程序是一个名为prova的exe项目,用于尝试dll。 在我决定在OptDll项目中插入一个新类(GlobalOutput)以创建所需的输出参数之前,我已经包含了正确的引用,所有工作都很好。当我构建项目OptDll时,不会发生错误,但当我构建整个解决方案时,我在prova项目中会出现以下错误:C++ 未解析的外部符号visual studio 2010错误,c++,unresolved-external,C++,Unresolved External,我已经用VisualStudio2010 professional实现了一个包含2个项目的解决方案;第一个名为OptDll的程序由一个动态库组成,其中包含一个我想要导出的方法,而第二个程序是一个名为prova的exe项目,用于尝试dll。 在我决定在OptDll项目中插入一个新类(GlobalOutput)以创建所需的输出参数之前,我已经包含了正确的引用,所有工作都很好。当我构建项目OptDll时,不会发生错误,但当我构建整个解决方案时,我在prova项目中会出现以下错误: Error 59
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
#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;
}
我读到类构造函数/析构函数可能有问题,但我没有修复它。
在兴趣代码下面
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);
}
}
相反,如果我取消注释total的定义,我还将获得:
9 IntelliSense:不允许使用不完整的类型c:\users\antonio\desktop\optdll\optdll\optfundll.cpp 131
谢谢您的可用性,我是C++编程新手。
您实际上没有导出您的类<代码> GULALOUTROX < < /P> 您需要:class OPTFUNDLL_API GlobalOutput
谢谢,但是现在我在cpp文件中出现了错误,如错误3错误C2027:使用未定义类型“optFun::myoptFun::GlobalOutput”c:\users\antonio\desktop\optdl\optdl\optfundll.cpp;此外,我注意到一条警告:警告1警告C4273:“optFun::myoptFun::scheduling”:不一致的dll链接c:\users\antonio\desktop\optdl\opttdll\opttfundll.cppi在我导出方法之前将代码插入optdl.h。@user3173091,你也可以导出myOptFun类。抱歉,Moo Juice,但我不明白…我认为myOptFun类已经被导出了,对吗?…可能是命名空间定义有问题???@user3173091,是的-你需要在prova项目中使用
optFun::GlobalOutput
作为定义。
class OPTFUNDLL_API GlobalOutput