error LNK2019 && fatal error LNK1120
我是cuda初学者,照着GPU高性能运算之CUDA这本书编程,第二章的小程序编译运行出现了如下两个错误:
错误1 error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用 LIBCMT.lib
错误2 fatal error LNK1120: 1 个无法解析的外部命令 G:\CUDA\example_2\Debug\example_2.exe
源代码如下:
//example_2.cu
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cutil.h>
#include "example_2_kernel.cu"
__host__ void
runTest(int argc, char** argv)
{
CUT_DEVICE_INIT(argc,argv); //启动CUDA
unsigned int mem_size = sizeof(float)* 4*4;
float* h_idata;
CUDA_SAFE_CALL(cudaMallocHost((void**)&h_idata,mem_size));
for(unsigned int i = 0;i<4;i++)
for(unsigned int j = 0;j<4;j++)
h_idata[i*4+j]=1.0f;
float* d_idata;
CUDA_SAFE_CALL(cudaMalloc((void**)&d_idata,mem_size));
CUDA_SAFE_CALL(cudaMemcpy(d_idata,h_idata,mem_size,cudaMemcpyHostToDevice));
float* d_odata;
CUDA_SAFE_CALL(cudaMalloc((void**)&d_odata,mem_size));
dim3 grid(2,2,1);
dim3 threads(2,2,1);
testKernel<<<grid,threads>>>(d_idata,d_odata,4,4);
CUT_CHECK_ERROR("Kernel execution failed");
float* h_odata;
CUDA_SAFE_CALL(cudaMallocHost((void**)&h_odata,mem_size));
CUDA_SAFE_CALL(cudaMemcpy(h_odata,d_odata,mem_size,cudaMemcpyDeviceToHost));
for (unsigned int i=0;i<4;i++)
{
for (unsigned int j=0;j<4;j++)
{
printf("%5.0f",h_odata[i*4+j]);
}
printf("\n");
}
CUDA_SAFE_CALL(cudaFreeHost(h_idata));
CUDA_SAFE_CALL(cudaFreeHost(h_odata));
CUDA_SAFE_CALL(cudaFree(d_idata));
CUDA_SAFE_CALL(cudaFree(d_odata));
}
//example_2_kernel.cu
#ifndef _EXAMPLE_2_KERNEL_H_
#define _EXAMPLE_2_KERNEL_H_
#define SDATA(index) CUT_BANK_CHECKER(sdata,index)
__global__ void testKernel(float* g_idata, float* g_odata, int width, int height)
{
__shared__ float sdata[4];
unsigned int bid_in_grid = __mul24(blockIdx.y,gridDim.x)+blockIdx.x;
unsigned int tid_in_block = __mul24(threadIdx.y,blockDim.x)+threadIdx.x;
unsigned int tid_in_grid_x = __mul24(blockDim.x,blockIdx.x) + threadIdx.x;
unsigned int tid_in_grid_y = __mul24(blockDim.y,blockIdx.y) + threadIdx.y;
unsigned int tid_in_grid = __mul24(tid_in_grid_y,width)+ tid_in_grid_x;
SDATA(tid_in_block)=g_idata[tid_in_grid];
__syncthreads();
g_odata[tid_in_grid]=SDATA(tid_in_block);
}
我实在不知道哪里出错啊,照着书上把代码敲上去的,为什么还是有错呢?
我的环境是cuda3.1
谢谢各位大牛了,帮忙解答解答