您的位置:首页 > Web前端

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

2017-12-26 13:30 2281 查看
最近在学习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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cuda
相关文章推荐