CUDA:无法解析的外部符号curandCreateGenerator/undefined reference to curandCreateGenerator

最近在学习CUDA中如何生成随机数时,用到了CUDA Toolkit Document中的一个示例代码:
http://docs.nvidia.com/cuda/curand/host-api-overview.html#performance-notes2
然而在直接使用这个代码进行编译时,直接遇到了四个错误。

错误

error LNK2019: 无法解析的外部符号 curandCreateGenerator,该符号在函数 main 中被引用
error LNK2019: 无法解析的外部符号 curandDestroyGenerator,该符号在函数 main 中被引用
error LNK2019: 无法解析的外部符号 curandSetPseudoRandomGeneratorSeed,该符号在函数 main 中被引用
error LNK2019: 无法解析的外部符号 curandGenerateUniform,该符号在函数 main 中被引用

或者:

undefined reference to `curandCreateGenerator'
undefined reference to `curandSetPseudoRandomGeneratorSeed'
undefined reference to `curandGenerate'
undefined reference to `curandDestroyGenerator'

解决方案

在网上查阅资料时,发现有人提到需要使用curand库:
https://stackoverflow.com/questions/11734578/curand-library-compiling-error-undefined-reference-to-functions
由于我使用的是Cmake组织工程,参考FindCUDA中的介绍:

CUDA_curand_LIBRARY   -- CUDA Random Number Generation library.
                         Only available for CUDA version 3.2+.

所以解决方案是使用CMake添加一句即可

target_link_libraries(host_random ${CUDA_curand_LIBRARY})

示例代码

https://github.com/Yannnnnnnnnnnn/cuda_random

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值