gpt4 book ai didi

c++ - 初学者 CUDA 程序中未解析的外部符号

转载 作者:可可西里 更新时间:2023-11-01 14:59:03 25 4
gpt4 key购买 nike

我创建一个新的 Win32 控制台应用程序作为一个空项目我正在使用 Visual Studio 2008 C++ 运行 Windows 7 64 位。我正在尝试从本文底部获取示例代码来构建:http://www.ddj.com/architect/207200659

我将 CUDA 构建规则 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, sizeof(float)*N, cudaMemcpyDeviceToDevice);
// retrieve data from device: b_d to b_h
cudaMemcpy(b_h, b_d, sizeof(float)*N, 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 main1>moveArrays.cu.obj : error LNK2019: unresolved external symbol cudaMemcpy referenced in function main1>moveArrays.cu.obj : error LNK2019: unresolved external symbol cudaMalloc referenced in function main1>moveArrays.cu.obj : error LNK2019: unresolved external symbol __cudaUnregisterFatBinary referenced in function __cudaUnregisterBinaryUtil1>moveArrays.cu.obj : error LNK2019: unresolved external symbol __cudaRegisterFatBinary referenced in function __sti____cudaRegisterAll_45_tmpxft_00001264_00000000_6_moveArrays_cpp1_ii_main1>D:\Stuff\Programming\Visual Studio 2008\Projects\CUDASandbox\x64\Debug\CUDASandbox.exe : fatal error LNK1120: 5 unresolved externals1>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 .

关于c++ - 初学者 CUDA 程序中未解析的外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2061715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com