我制作了一个 C++ OpenCL 项目,用于在 GPU 上处理一些代码。我需要在 C# 中访问这个项目,所以我很自然地使用 C#/CLR 项目来链接 C# 和 C++ 代码。
以下代码在没有传递参数时有效,在我添加一些参数时无效:
作品:
命令行:
类库1.cpp:
#include "stdafx.h"
#include "ClassLibrary1.h"
#include "../OpenCLProject1/OpenCL.h"
namespace ClassLibrary1
{
int Class1::Method(int value1, int value2)
{
OpenCL::TestMethod();
return 0;
}
}
类库1.h:
using namespace System;
namespace ClassLibrary1 {
public ref class Class1
{
public:
static int Method(int value1, int value2);
};
}
开放式CL:
OpenCL.cpp:
#include "OpenCL.h"
void OpenCL::TestMethod()
{
}
OpenCL.h:
class OpenCL
{
public:
static void TestMethod();
};
不工作:
命令行:
类库1.cpp:
#include "stdafx.h"
#include "ClassLibrary1.h"
#include "../OpenCLProject1/OpenCL.h"
namespace ClassLibrary1
{
int Class1::Method(int value1, int value2)
{
return OpenCL::TestMethod(value1, value2);
}
}
类库1.h:
using namespace System;
namespace ClassLibrary1 {
public ref class Class1
{
public:
static int Method(int value1, int value2);
};
}
开放式CL:
OpenCL.cpp:
#include "OpenCL.h"
int OpenCL::TestMethod(int value1, int value2)
{
return value1 + value2;
}
OpenCL.h:
class OpenCL
{
public:
static int TestMethod(int value1, int value2);
};
我得到很好的 LNK2019 和 LNK2028 错误:
ClassLibrary1.obj : error LNK2028: jeton non rÚsolu (0A000005) "public: static int __cdecl OpenCL::TestMethod(int,int)" (?TestMethod@OpenCL@@$$FSAHHH@Z) rÚfÚrencÚ dans la fonction "public: static int __clrcall ClassLibrary1::Class1::Method(int,int)" (?Method@Class1@ClassLibrary1@@$$FSMHHH@Z)
我在 Windows 10 b1903 上使用 Visual Studio 2015 Pro。