从DLL C++导入函数时出现问题.LNK 2001

Issue importing functions from DLL C++. LNK 2001

本文关键字:问题 LNK 2001 DLL C++ 导入 函数      更新时间:2023-10-16

我有两个项目。一个创建DLL,另一个应该使用DLL中声明的函数,但我在实现这一点时遇到了问题。

在DLL项目中,我有以下声明:

using namespace XClass;
extern "C" __declspec(dllexport) int Compute(XClass::XClassInput input, XClassOutput &XClassOutput);
extern "C" __declspec(dllexport) int Init( string configFileName);
class xclass
{
public:
    xclass(void);
    xclass(constellation &Constellation, XClass::XClassConfig &XClassConfig);
    void   ComputeWeightingMatrix(constellation &xclass_constellation, char flagIntCont);
    void   ComputeGMatrix(constellation &Constellation, XClass::XClassInput &input);
private:
    int _numberOfSystemStates;
};

在必须使用DLL函数的项目中,我有这样的:

int _tmain(int argc, _TCHAR* argv[])
{
    XClass::XClassConfig xClassConfig;
    XClassOutput xClassOutput;
    XClass::XClassInput input;
    init(input, xClassOutput ); 
    constellation* class_constellation = new constellation(input, xClassConfig);
    xclass* algorithm = new xclass(*xclass_constellation, xClassConfig);

     algorithm->ComputeWeightingMatrix(*xclass_constellation,  'i');

    return 0;
}

ComputeWeighting Matrix函数的代码:

    void xclass::ComputeWeightingMatrix(constellation &Constellation, char flagIntCont)
    {
        double sigma = 0.0;
        long error;
            ...
    }

当我尝试构建时,我得到了他的:

错误LNK2001:未解析的外部符号"public:void __thiscall xclass::ComputeWeightingMatrix(class constellation&,char)"(?ComputeWeightingMatrix@xclass@@$$FQAEXAAVconstellation@@D@Z)

在Chat中进行了一些讨论后,发现这个问题的解决方案有两部分:

  1. 需要使用DLL类中的存根库
  2. 需要使用class __declspec(dllexport) XClass来确保导出类中的功能