我做了一个C++ OpenCL项目,用于处理GPU上的一些代码。我需要在C语言中访问这个项目,所以我自然地使用C语言的CL/CLR项目来链接C和C++代码。
以下代码在未传递任何参数时有效,在添加一些参数时无效:
作品:
CLI:
班级图书馆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);
};
}
OpenCL:
OpenCL。cpp:
#include "OpenCL.h"
void OpenCL::TestMethod()
{
}
OpenCL。h:
class OpenCL
{
public:
static void TestMethod();
};
不起作用:
CLI:
班级图书馆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:
使用名称空间系统;
命名空间类库1{
公共参考类1
{
公众:
静态int方法(int-value1,int-value2);
};
}
OpenCL:
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。