c – 初学者CUDA程序中未解决的外部符号

前端之家收集整理的这篇文章主要介绍了c – 初学者CUDA程序中未解决的外部符号前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建一个新的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 <stdio.h>
#include <assert.h>
#include <cuda.h>
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<N; i++) {
      a_h[i] = 10.f+i;
      b_h[i] = 0.f;
   }
   // send data from host to device: a_h to a_d 
   cudaMemcpy(a_d,a_h,sizeof(float)*N,cudaMemcpyHostToDevice);
   // copy data within device: a_d to b_d
   cudaMemcpy(b_d,a_d,cudaMemcpyDeviceToDevice);
   // retrieve data from device: b_d to b_h
   cudaMemcpy(b_h,b_d,cudaMemcpyDeviceToHost);
   // check result
   for (i=0; i<N; i++)
      assert(a_h[i] == b_h[i]);
   // cleanup
   free(a_h); free(b_h); 
   cudaFree(a_d); cudaFree(b_d);
}

当我建立我得到这些错误

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程序.我知道我在这里缺少一些简单的东西,但它是什么呢?

解决方法

我想你缺少链接到正确的图书馆.
确保您在“配置属性 – >链接器 – >输入”下添加了CUDA库.
参考 this.
原文链接:https://www.f2er.com/c/113237.html

猜你在找的C&C++相关文章