CURAND 库 - 编译错误 - 未定义的函数引用 [英] CURAND Library - Compiling Error - Undefined reference to functions

查看:41
本文介绍了CURAND 库 - 编译错误 - 未定义的函数引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,我正在尝试使用 nvcc 进行编译.

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

代码:

#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;
}

这是我收到的输出:

$ 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

我最初的猜测是由于某种原因 CURAND 库没有正确安装或者找不到 curand.h 头文件.

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.

谢谢!

推荐答案

@Wilo Maldonado:只需使用链接器标志 -lcurand 和另外 -L/path/to/cuda/libs 如果你还没有它

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

这篇关于CURAND 库 - 编译错误 - 未定义的函数引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆