I separate a class source and kernel source in visual studio, however, i got undefined reference errors:
Error Undefined reference to ‘_ZN7TestOneC1Ev’ in ‘x64/Release/kernel.cpp.obj’ gp_gpu
testone.h
#pragma once
#include “cuda_runtime.h”
class TestOne {
public:
host device TestOne();
host device ~TestOne();
device virtual void AddOne(int a,int b,int& c);
host device TestOne* CreateOne();
int i;
};
testone.cpp
#include “testone.h”
host device TestOne::TestOne():i(10) {}
host device TestOne::~TestOne() {}
device void TestOne::AddOne(int a,int b,int& c) {
c=a + b;
i++;
}
host device TestOne* TestOne::CreateOne() {
return new TestOne;
}
kernel.cpp
… header file
#include “testone.h”
global void addKernel(TestOne** pone, int *c, const int *a, const int *b)
{
int i = threadIdx.x;
(*pone)->AddOne(a[i],b[i],c[i]);
if(*pone) printf("@%d-> %d \n ",threadIdx.x,(*pone)->i);
}
global void createObj(TestOne** pone)
{
if(threadIdx.x == 0 && blockIdx.x == 0) {
*pone= new TestOne;
}
if(*pone) printf("@%d-> %d \n ",threadIdx.x,(*pone)->i);
//return 0;
}
int main()
{
…
int dev_a = 0;
int dev_b = 0;
int dev_c = 0;
TestOne pone;
…
cudaMalloc((void*)&pone,sizeof(TestOne**));
createObj << <1,1 >> >(pone);
cudaDeviceSynchronize();
cudaMemcpy(*pone,&onecpu,1 * sizeof(TestOne),cudaMemcpyHostToDevice);
addKernel<<<1, size>>>(pone, dev_c, dev_a, dev_b);
return cudaStatus;
}
project:
<?xml version="1.0" encoding="utf-8"?> Release x64 {9BDE6162-4850-4C96-A24B-86B801D8D9AD} gp_gpu 10.0.16299.0 Application false true MultiByte v141 Level3 MaxSpeed true true WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true true true Console cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 64 true Static compile %(AdditionalDependencies)