CUDA:无法解析的外部符号curandCreateGenerator/undefined reference to curandCreateGenerator
来源:互联网 发布:通用顶级域名有哪些 编辑:程序博客网 时间:2024/06/06 03:48
最近在学习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
阅读全文