从DLL C ++发出导入函数。 LNK 2001

时间:2013-07-17 09:59:46

标签: c++ dll dllimport dllexport lnk2001

我有两个项目。一个创建一个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)

1 个答案:

答案 0 :(得分:1)

在聊天中进行了一些讨论之后,事实证明解决这个问题有两个部分:

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