简体   繁体   English

从DLL C ++导入函数。 2001年

[英]Issue importing functions from DLL C++. LNK 2001

I have two projects. 我有两个项目。 One creates a DLL and the other should use functions declared in the DLL, but I have problems implementing this. 一个创建一个DLL,另一个应该使用在DLL中声明的函数,但是实现此问题。

In the DLL project I have these declarations: 在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;
};

In the project that has to use the DLL functions I have this: 在必须使用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;
}

The code for the ComputeWeighting Matrix function: ComputeWeighting Matrix函数的代码:

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

            ...
    }

When I try to build I get his: 当我尝试构建时,我得到了他:

error LNK2001: unresolved external symbol "public: void __thiscall xclass::ComputeWeightingMatrix(class constellation &,char)" (?ComputeWeightingMatrix@xclass@@$$FQAEXAAVconstellation@@D@Z) 错误LNK2001:无法解析的外部符号“ public:void __thiscall xclass :: ComputeWeightingMatrix(class星座和,char)”(?ComputeWeightingMatrix @ xclass @@ $$ FQAEXAAVconstellation @@ D @ Z)

After some discussion in Chat, it turns out there are two parts to the solution of this problem: 在“聊天”中进行了一些讨论之后,事实证明,解决此问题有两个部分:

  1. Need to use the stub library from the DLL class. 需要使用DLL类中的存根库。
  2. Need to use class __declspec(dllexport) XClass to ensure the functionality from the class is exported. 需要使用class __declspec(dllexport) XClass来确保从该类中导出功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM