c++ error 2019LNK2019: 无法解析的外部符号_mainfatal error 2019LNK112

c++ - Unresolved external symbols in beginners CUDA program - Stack Overflow
Join Stack Overflow to learn, share knowledge, and build your career.
or sign in with
I create a new Win32 Console App as an empty project
I am running Windows 7 64bit with Visual Studio 2008 C++.
I am trying to get the sample code from the bottom of this article to build:
I add CUDA Build Rule v2.3.0 to the project's custom build rules.
It is the only thing with a checkbox in the available rule files list
I create moveArrays.cu in the Source Files (folder/filter???)
In that file I add the following code:
// 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;
// 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);
When I build I get these errors:
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_00000_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 ==========
I can compile and run the example CUDA programs that came with the SDK.
I know I am missing something simple here, but what is it?
4,2951664110
I guess you are missing to link to the correct library.
Make sure you have the CUDA library added under "Configuration Properties->Linker->Input".
Two things are needed:
Add cuda path:
Go: "Configuration Properties->Linker->General->Additional Libary Directories" and add $(CudaToolkitLibDir) to the list.
Add cuda realtime library:
Go: "Solution Properties->Linker->Input->Additional Dependencies" and add cudart.lib to the list.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Upcoming Events
ends Mar 27
Stack Overflow works best with JavaScript enabled错误 2 error LNK1120: 1 个无法解析的外部命令_百度知道
错误 2 error LNK1120: 1 个无法解析的外部命令
编译通过了,但是生成时出错了!
我有更好的答案
但是找不到实现.另一个原因是函数的声明和实现都放在头文件中了,一般要把声明放头文件中,实现放在cpp文件中。2,只有这个函数的声明。有两个原因,连接不成功,没有包含这个函数的实现(实现一般放在cpp文件中的)。所以只能通过编译这个问题的原因是有头文件。这样每个#include该头文件的文件都会有一份该函数的实现,连接的时候,连接器不知道连接哪一个实现,于是报错:1.只包含了头文件
高级软件工程师
但是找不到实现.另一个原因是函数的声明和实现都放在头文件中了,一般要把声明放头文件中,实现放在cpp文件中。2,只有这个函数的声明。有两个原因,连接不成功,没有包含这个函数的实现(实现一般放在cpp文件中的)。所以只能通过编译这个问题的原因是有头文件。这样每个#include该头文件的文件都会有一份该函数的实现,连接的时候,连接器不知道连接哪一个实现,于是报错:1.只包含了头文件
1条折叠回答
为您推荐:
其他类似问题
外部命令的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。

我要回帖

更多关于 vs error lnk2019 的文章

 

随机推荐