我创建一个新的Win32控制台应用程序作为一个空项目我使用Visual Studio 2008 C++运行Windows 7 64位.我试图从本文底部获取示例代码来构建:http://www.ddj.com/architect/207200659
我将CUDA Build Rule v2.3.0添加到项目的自定义构建规则中.这是唯一一个在可用规则文件列表中有一个复选框的东西
我在源文件(文件夹/过滤器???)中创建moveArrays.cu
在该文件中,我添加以下代码:
// moveArrays.cu // // demonstrates CUDA interface to data allocation on device (GPU) // and data movement between host (CPU) and device. #include#include #include int main(void) { float *a_h, *b_h; // pointers to host memory float *a_d, *b_d; // pointers to device memory int N = 14; int i; // allocate arrays on host a_h = (float *)malloc(sizeof(float)*N); b_h = (float *)malloc(sizeof(float)*N); // allocate arrays on device cudaMalloc((void **) &a_d, sizeof(float)*N); cudaMalloc((void **) &b_d, sizeof(float)*N); // initialize host data for (i=0; i 当我构建时,我得到这些错误:
1>------ Build started: Project: CUDASandbox, Configuration: Debug x64 ------ 1>Linking... 1>moveArrays.cu.obj : error LNK2019: unresolved external symbol cudaFree referenced in function main 1>moveArrays.cu.obj : error LNK2019: unresolved external symbol cudaMemcpy referenced in function main 1>moveArrays.cu.obj : error LNK2019: unresolved external symbol cudaMalloc referenced in function main 1>moveArrays.cu.obj : error LNK2019: unresolved external symbol __cudaUnregisterFatBinary referenced in function __cudaUnregisterBinaryUtil 1>moveArrays.cu.obj : error LNK2019: unresolved external symbol __cudaRegisterFatBinary referenced in function __sti____cudaRegisterAll_45_tmpxft_00001264_00000000_6_moveArrays_cpp1_ii_main 1>D:\Stuff\Programming\Visual Studio 2008\Projects\CUDASandbox\x64\Debug\CUDASandbox.exe : fatal error LNK1120: 5 unresolved externals 1>Build log was saved at "file://d:\Stuff\Programming\Visual Studio 2008\Projects\CUDASandbox\CUDASandbox\x64\Debug\BuildLog.htm" 1>CUDASandbox - 6 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========我可以编译并运行SDK附带的示例CUDA程序.我知道我在这里错过了一些简单的东西,但它是什么?
1> sand..:我想你错过了链接到正确的库.确保在"Configuration Properties-> Linker-> Input"下添加了CUDA库.请参阅此.
你是对的.我必须将"$(CUDA_LIB_PATH); ../../ common/lib"添加到Configuration Properties-> Linker-> General-> Additional Libary Directories,将"cudart.lib"添加到Configuration Properties-> Linker-> Input- >附加依赖项
2> betontalpfa..:需要做两件事:
添加CUDA路径:
Go:"Configuration Properties-> Linker-> General-> Additional Libary Directories"并添加$(CudaToolkitLibDir)
到列表中.添加CUDA运行时库:
转到:"解决方案属性 - >链接器 - >输入 - >附加依赖关系"并添加cudart.lib
到列表中.