gpt4 book ai didi

c++ - 从 DLL C++ 发出导入函数。领航2001

转载 作者:行者123 更新时间:2023-11-28 07:31:03 25 4
gpt4 key购买 nike

我有两个项目。一个创建一个 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 类中的 stub 库。
  2. 需要使用 class __declspec(dllexport) XClass 来确保导出类的功能。

关于c++ - 从 DLL C++ 发出导入函数。领航2001,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17696751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com