Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
912 views
in Technique[技术] by (71.8m points)

cuda - CURAND Library - Compiling Error - Undefined reference to functions

I have the following code which I am trying to compile using nvcc.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <cuda.h>
#include <curand.h>

int main(void)
{
    size_t n = 100;
    size_t i;
    int *hostData;
    unsigned int *devData;
    hostData = (int *)calloc(n, sizeof(int));
    curandGenerator_t gen;
    curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_MRG32K3A);
    curandSetPseudoRandomGeneratorSeed(gen, 12345);
    cudaMalloc((void **)&devData, n * sizeof(int));
    curandGenerate(gen, devData, n);
    cudaMemcpy(hostData, devData, n * sizeof(int), cudaMemcpyDeviceToHost);
    for(i = 0; i < n; i++)
    {
        printf("%d ", hostData[i]);
    }
    printf("
");
    curandDestroyGenerator (gen);
    cudaFree ( devData );
    free ( hostData );
    return 0;
}

This is the output I receive:

$ nvcc -o RNG7 RNG7.cu
/tmp/tmpxft_00005da4_00000000-13_RNG7.o: In function `main':
tmpxft_00005da4_00000000-1_RNG7.cudafe1.cpp:(.text+0x6c): undefined reference to `curandCreateGenerator'
tmpxft_00005da4_00000000-1_RNG7.cudafe1.cpp:(.text+0x7a): undefined reference to `curandSetPseudoRandomGeneratorSeed'
tmpxft_00005da4_00000000-1_RNG7.cudafe1.cpp:(.text+0xa0): undefined reference to `curandGenerate'
tmpxft_00005da4_00000000-1_RNG7.cudafe1.cpp:(.text+0x107): undefined reference to `curandDestroyGenerator'
collect2: ld returned 1 exit status

My initial guess is that for some reason the CURAND Library is not properly installed or that it cannot find the curand.h header file.

Please let me know what I should look for or how to solve my problem.

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

@Wilo Maldonado: just use a linker flag -lcurand and additionally -L/path/to/cuda/libs if you do not have it already


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...