3

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)

Community
  • 1
  • 1
Khalif21
  • 97
  • 2
  • 11

2 Answers2

3

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

Rudolfs Bundulis
  • 11,636
  • 6
  • 33
  • 71
  • i have added it under Linker->Input->Additional Dependencies. – Khalif21 Jun 16 '15 at 12:06
  • @Khalif21 any chance of using the wrong bitness? Can you turn on verbose linker output in the property pages and paste the output of the linking stage here? – Rudolfs Bundulis Jun 16 '15 at 12:10
  • I have added it under Linker->Input->Additional Dependencies. I also have tried to add its path _C:\Program Files\NVIDIA Corporation\Installer2\CUDAToolkit_7.0.{CFA7F9AA-52A1-40E0-97FA-71C041D185CF}\lib\x64_ to CUDA Linker->General->Additional Library Directories. It has not resolve the problem. – Khalif21 Jun 16 '15 at 12:20
  • _@Rudolfs_ This is the Linker output _cudart.lib;C:\Program Files\NVIDIA Corporation\Installer2\CUDAToolkit_7.0.{CFA7F9AA-52A1-40E0-97FA-71C041D185CF}\lib\x64\curand.lib;%(AdditionalDependencies)_. – Khalif21 Jun 16 '15 at 12:25
  • Is your project 32bit or 64bit? And this is not what I meant with verbose output. You can turn on verbose output in the linker property pages so that the linker prints everything it does to the print log. Also, do not use the full directory, just add curand.lib, without the path. – Rudolfs Bundulis Jun 16 '15 at 12:45
  • @Khalif21 I edited the answer to show how to enable verbose linker output. – Rudolfs Bundulis Jun 16 '15 at 12:47
  • _@Rudolfs_ The Output of the Linking Stage too long to paste here. – Khalif21 Jun 16 '15 at 13:05
  • @Khalif21 well, what do you see yourself? Any relevant info on curand.lib? – Rudolfs Bundulis Jun 16 '15 at 13:18
  • "@Rudolfs" My Project is Project 32 Bit. The Output Extension is .dll . I get this Lines in log file : 'Unused libraries: C:\Program Files\NVIDIA Corporation\Installer2\CUDAToolkit_7.0.{CFA7F9AA-52A1-40E0-97FA-71C041D185CF}\lib\x64\curand.lib' – Khalif21 Jun 16 '15 at 13:28
  • @Khalif21 that is why I told you not to use the full path. You are linking a 64bit library with your 32bit dll. How do you expect it to work? Remove the path and just leave curand.lib in the linker inputs, it should pick it up from the same place it gets cudart.lib. – Rudolfs Bundulis Jun 16 '15 at 13:35
  • _@Rudolfs_ Previously, I have tried it, but i get this Error 'Error 2 error LNK1104: cannot open file 'curand.lib' F:\New\Eks\Visual Studio 2013\PEOPLE PROJECTS\RNGTests\CURANDRNGLib\LINK CURANDRNGLib' . I also have tried to copy it to Project Directory and Project Output Directory. but it has not resolve the problem. – Khalif21 Jun 16 '15 at 13:52
  • @Khalif21 is curand.lib not in the same directory that cudart.lib is? if not add full path, but to the 32bit version, not the 64bit. – Rudolfs Bundulis Jun 16 '15 at 13:57
  • _@Rudolfs_ Yes, it is. It has not resolve the Problem. – Khalif21 Jun 16 '15 at 14:06
  • @Khalif21 ok weird, if you have the 32bit CUDA GPU computing toolkit and cudart.lib is picked up correctly without a full path it means that the path to libraries is specified in the additional library directories field. Not sure why curand.lib is not picked up as well but you have provided too little information to resolve this. – Rudolfs Bundulis Jun 16 '15 at 14:11
  • _@Rudolfs_ I think, there is a mistake in the code themselves, not curand.lib. Because, I could build Other cuRand project. – Khalif21 Jun 16 '15 at 14:59
  • 1
    You have link errors, those are not caused by problems in your code. Your settings are wrong. You should go through all the settings in the working example and compare with your broken project to locate the problem. And you should try to build in 64 bit mode. – Tom Jun 17 '15 at 05:38
1

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)