3
votes

I have researched for hours,

  1. MSDN Microsoft - Linker Tools Error LNK2019
  2. How to solve the error LNK2019: unresolved external symbol - function?
  3. What is an undefined reference/unresolved external symbol error and how do I fix it?
  4. Error LNK2019: unresolved external symbol _wWinMain@16 referenced in function ___tmainCRTStartup
  5. How to get rid of this error: "MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup"

    but have not found a way to resolve the following error,

Error	1	error LNK2019: unresolved external symbol _curandCreateGenerator@8 referenced in function _GPU_RNG	F:\New\Eks\Visual Studio 2013\PEOPLE PROJECTS\RNGTests\CURANDRNGLib\CURANDRNG.cu.obj	CURANDRNGLib
Error	2	error LNK2019: unresolved external symbol _curandCreateGeneratorHost@8 referenced in function _CPU_RNG	F:\New\Eks\Visual Studio 2013\PEOPLE PROJECTS\RNGTests\CURANDRNGLib\CURANDRNG.cu.obj	CURANDRNGLib
Error	3	error LNK2019: unresolved external symbol _curandDestroyGenerator@4 referenced in function _GPU_RNG	F:\New\Eks\Visual Studio 2013\PEOPLE PROJECTS\RNGTests\CURANDRNGLib\CURANDRNG.cu.obj	CURANDRNGLib
Error	4	error LNK2019: unresolved external symbol _curandSetPseudoRandomGeneratorSeed@12 referenced in function _GPU_RNG	F:\New\Eks\Visual Studio 2013\PEOPLE PROJECTS\RNGTests\CURANDRNGLib\CURANDRNG.cu.obj	CURANDRNGLib
Error	5	error LNK2019: unresolved external symbol _curandGenerateUniform@12 referenced in function _GPU_RNG	F:\New\Eks\Visual Studio 2013\PEOPLE PROJECTS\RNGTests\CURANDRNGLib\CURANDRNG.cu.obj	CURANDRNGLib

CURANDRNGLib.cu

#include <cuda.h>
#include <cuda_runtime.h>
#include <curand.h>
#include <curand_kernel.h>

using namespace std;
extern "C" __declspec(dllexport) void __cdecl GPU_RNG(float* , unsigned int , unsigned int);
extern "C" __declspec(dllexport) void __cdecl CPU_RNG(float* , unsigned int , unsigned int);


extern void GPU_RNG(float * h_randomData, unsigned int dataCount, unsigned int mainSeed)
{
	float * d_randomData = 0;

	//allocate device memory
	size_t randomDataSize = dataCount * sizeof(float);
	cudaMalloc((void**)&d_randomData, randomDataSize);

	curandGenerator_t m_prng;
	//Create a new generator
	curandCreateGenerator(&m_prng, CURAND_RNG_PSEUDO_DEFAULT);
	//Set the generator options
	curandSetPseudoRandomGeneratorSeed(m_prng, (unsigned long) mainSeed);
	//Generate random numbers
	curandGenerateUniform(m_prng, d_randomData, dataCount);
	//Copy memory back to the device
	cudaMemcpy(h_randomData, d_randomData, randomDataSize, cudaMemcpyDeviceToHost);
	//Clean
	curandDestroyGenerator(m_prng);
	//free device memory
	cudaFree(d_randomData);
}

extern void CPU_RNG(float * h_randomData, unsigned int dataCount, unsigned int mainSeed)
{
	curandGenerator_t m_prng;
	//Create a new generator
	curandCreateGeneratorHost(&m_prng,CURAND_RNG_PSEUDO_DEFAULT);
	//Set the generator options
	curandSetPseudoRandomGeneratorSeed(m_prng, (unsigned long) mainSeed);
	//Generate random numbers
	curandGenerateUniform(m_prng, h_randomData, dataCount);
	//Clean
	curandDestroyGenerator(m_prng);
}

Should I add a #include? (I'm not good at english very much)

2
can you build any of the CUDA sample projects that use CURAND? If so, you can study those to understand proper project settings.Robert Crovella
@Robert Yes, i can.Khalif21
Those projects have all the necessary settings to use CURAND without getting the undefined reference errors.Robert Crovella
So that means you should be able to study those projects (or just re-use one of them) and get your issue sorted out. AFAIK none of those projects are creating a dll, but that is a separate issue and presumably you have that figured out (you don't seem to be asking about it here).Robert Crovella
@Robert I have know it.Khalif21

2 Answers

1
votes

I guess you might have developed your code on Win32 platform. There is only basic CUDA API support but no CURAND library support on Win32. You can try switching to developing a 64-bit version. (Project -> Properties -> change the platform option on top)

3
votes

You should be linking against curand.lib - add it in the property sheets under Linker -> Input -> Additional Dependencies.

This is how you turn on verbose linker output: enter image description here