I am trying to add a CUDA file to my existing C++ Visual Studio 2013 project. I have the CUDA 8.0 SDK installed, I have created a new .cu file, but I can NOT set its Item Type to CUDA/C++ in the CUDA file properties. by compling the project, I’ve got a lot of errors like this:
.NETFramework,Version=v4.5.1.AssemblyAttributes.cpp
2>GpuManagerSdkWrapper.obj : error LNK2028: Nicht aufgelöstes Token (0A00002A) ““public: int __cdecl CudaWrapper::mycudafunction(void)” (?mycudafunction@CudaWrapper@@$$FQEAAHXZ)”, auf das in Funktion ““public: int __cdecl diondo_GpuManager::CudaManager::test(void)” (?test@CudaManager@diondo_GpuManager@@$$FQEAAHXZ)” verwiesen wird.
2>GpuManagerSdkWrapper.obj : error LNK2028: Nicht aufgelöstes Token (0A00002B) ““public: __cdecl CudaWrapper::CudaWrapper(void)” (??0CudaWrapper@@$$FQEAA@XZ)”, auf das in Funktion ““public: int __cdecl diondo_GpuManager::CudaManager::test(void)” (?test@CudaManager@diondo_GpuManager@@$$FQEAAHXZ)” verwiesen wird.
2>GpuManagerSdkWrapper.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ““public: __cdecl CudaWrapper::CudaWrapper(void)” (??0CudaWrapper@@$$FQEAA@XZ)” in Funktion ““public: int __cdecl diondo_GpuManager::CudaManager::test(void)” (?test@CudaManager@diondo_GpuManager@@$$FQEAAHXZ)”.
2>GpuManagerSdkWrapper.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ““public: int __cdecl CudaWrapper::mycudafunction(void)” (?mycudafunction@CudaWrapper@@$$FQEAAHXZ)” in Funktion ““public: int __cdecl diondo_GpuManager::CudaManager::test(void)” (?test@CudaManager@diondo_GpuManager@@$$FQEAAHXZ)”.
2>E:\Transfer\La\CT-Software\diondo-CT-Program\GUI\WpfGui\x64\Release\GpuManagerSdkWrapper.dll : fatal error LNK1120: 4 nicht aufgelöste Externe
========== Alles neu erstellen: 1 erfolgreich, 1 fehlerhaft, 0 übersprungen ==========
My simple code looks like this:
the Header File
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// CudaHeader.h
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
#ifndef _MyCudaWrapper_H_
#define _MyCudaWrapper_H_
extern "C"
{
#include <string.h>
#include <math.h>
}
extern "C" {
/*CUDA prototype, can be changed to "cudaadvance" or the like*/
int myfunction_(void);
}
class MyCudaWrapper
{
public:
MyCudaWrapper(); /* Initialized with defaults setup */
~MyCudaWrapper(); /* Free memory */
int Mycudafunction(void);
private:
};
#endif
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// CudaWrapper.cu
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
include "stdafx.h"
#include "CudaWrapper.h"
#include <stdio.h>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
//
#include <iostream>
#include <fstream>
using namespace std;
// Includes for IntelliSense
#define _SIZE_T_DEFINED
#ifndef __CUDACC__
#define __CUDACC__
#endif
#ifndef __cplusplus
#define __cplusplus
#endif
/********************/
/* CUDA ERROR CHECK */
/********************/
#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, char *file, int line, bool abort = true)
{
if (code != cudaSuccess)
{
fprintf(stderr, "GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
if (abort) exit(code);
}
}
__global__ void Mykernel(void)
{
}
extern "C" int myfunction_(void)
{
Mykernel << <1, 1 >> >();
//printf("Hello, World!\n");
return 3;
}
CudaWrapper::CudaWrapper()
{
}
int CudaWrapper::mycudafunction()
{
return myfunction_();
}
What does it mean by unresolved externals? and What is the right way too Integrating CUDA into a C++ application to use existing C++ class
Thanks in advance!
AminLadal