Hello
I am having this problem, i am making a function cuda dll, i can make dll’s with no problem (non-cuda), i also can make cuda programs, (non-dll) version, with no problem, all under 2005vs, but when i combine the two, i get errors.
so basically this is the code, it is code from cuda_example3. posted on the web, so i was converting it to a dll function library,
here is the dll part:
// CudaFuncsDll.h
#ifndef CUDAFUNCSDll_H
#define CUDAFUNCSDll_H
#include
#if defined DLL_EXPORT
#define DECLDIR __declspec(dllexport)
#else
#define DECLDIR __declspec(dllexport)
#endif
extern “C”
{
DECLDIR global void square_array( float *a, int N );
}
#endif
here is the function body
#include “CudaFuncsDll.h”
using namespace std;
namespace CudaFuncs
{
global void square_array( float *a, int N )
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if ( idx < N )
a[idx] = a[idx] * a[idx];
}
}
compiler output is:
1>------ Build started: Project: CudaFuncsDll, Configuration: Debug Win32 ------
1>Compiling with CUDA Build Rule…
1>“C:\CUDA\bin\nvcc.exe” -ccbin “C:\Program Files\Microsoft Visual Studio 8\VC\bin” -I"C:\CUDA\include" -I"./" -I"…/…/common/inc" -I"…/…/…/shared/inc" -I"C:\Documents and Settings\jkane\My Documents\Visual Studio 2005\Projects\DynamicCudaLibrary\CudaFuncsDll" -Xcompiler "/EHsc /W3 /nologo /O2 /Zi /MT " -maxrregcount=32 -gencode=arch=compute_10,code="sm_10,compute_10" -gencode=arch=compute_20,code="sm_20,compute_20" --compile -o “Debug\CudaFuncsDll.cu.obj” “c:\Documents and Settings\jkane\My Documents\Visual Studio 2005\Projects\DynamicCudaLibrary\CudaFuncsDll\CudaFuncsDll.cu”
1>CudaFuncsDll.cu
1>tmpxft_000012e0_00000000-6_CudaFuncsDll.compute_10.cudafe1.gpu
1>tmpxft_000012e0_00000000-10_CudaFuncsDll.compute_10.cudafe2.gpu
1>CudaFuncsDll.cu
1>tmpxft_000012e0_00000000-3_CudaFuncsDll.compute_20.cudafe1.gpu
1>tmpxft_000012e0_00000000-14_CudaFuncsDll.compute_20.cudafe2.gpu
1>CudaFuncsDll.cu
1>tmpxft_000012e0_00000000-6_CudaFuncsDll.compute_10.cudafe1.cpp
1>tmpxft_000012e0_00000000-20_CudaFuncsDll.compute_10.ii
1>Build log was saved at “file://c:\Documents and Settings\jkane\My Documents\Visual Studio 2005\Projects\DynamicCudaLibrary\CudaFuncsDll\Debug\BuildLog.htm”
1>CudaFuncsDll - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
so far so good, compiles fine, no errors,
but when i try to build the main i get an error
/ MyExecRefsDll.cpp : Defines the entry point for the console application.
//
#include “stdafx.h”
#include
#include <stdio.h>
#include <cuda.h>
#include “CudaFuncsDll.h”
using namespace std;
// main routine that executes on the host
int _tmain(int argc, _TCHAR* argv)
{
float *a_h, *a_d; // Pointer to host & device arrays
const int N = 10; // Number of elements in arrays
size_t size = N * sizeof( float );
a_h = (float *)malloc( size ); // Allocate array on host
cudaMalloc( (void **)&a_d, size ); // Allocate array on device
// Initialize host array and copy it to CUDA device
for ( int i = 0; i < N; i++ )
a_h[i] = (float)i;
cudaMemcpy( a_d, a_h, size, cudaMemcpyHostToDevice );
// Do calculation on device:
int block_size = 4;
int n_blocks = N / block_size + ( N % block_size == 0 ? 0 : 1 );
square_array <<< n_blocks, block_size >>> ( a_d, N );
// xor_arrays <<< n_blocks, block_size >>> ( a_d, N );
// Retrieve result from device and store it in host array
cudaMemcpy( a_h, a_d, sizeof( float ) * N, cudaMemcpyDeviceToHost );
// Print results
for ( int i = 0; i < N; i++ )
printf( "%d %f\n", i, a_h[i] );
// Cleanup
free( a_h );
cudaFree( a_d );
return 0;
}
the compiler/linker output is:
1>------ Build started: Project: CudaFuncsDll, Configuration: Debug Win32 ------
1>Linking…
1>LINK : fatal error LNK1104: cannot open file ‘cudart.lib’
1>Build log was saved at “file://c:\Documents and Settings\jkane\My Documents\Visual Studio 2005\Projects\DynamicCudaLibrary\CudaFuncsDll\Debug\BuildLog.htm”
1>CudaFuncsDll - 1 error(s), 0 warning(s)
2>------ Build started: Project: MyExecRefsDll, Configuration: Debug Win32 ------
2>Compiling with CUDA Build Rule…
2>“C:\CUDA\bin\nvcc.exe” -ccbin “C:\Program Files\Microsoft Visual Studio 8\VC\bin” -I"C:\CUDA\include" -I"./" -I"…/…/common/inc" -I"…/…/…/shared/inc" -I"C:\CUDA\lib" -I"“C:\Documents and Settings\All Users\Application Data\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\common\lib” -I"C:\Documents and Settings\jkane\My Documents\Visual Studio 2005\Projects\DynamicCudaLibrary\CudaFuncsDll" -I"C:\Documents and Settings\All Users\Application Data\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\common\lib" -Xcompiler "/EHsc /W3 /nologo /O2 /Zi /MT " -maxrregcount=32 -gencode=arch=compute_10,code="sm_10,compute_10" -gencode=arch=compute_20,code="sm_20,compute_20" --compile -o “Debug\MyExecRefsDll.cu.obj” “c:\Documents and Settings\jkane\My Documents\Visual Studio 2005\Projects\DynamicCudaLibrary\MyExecRefsDll\MyExecRefsDll.cu”
2>nvcc Ç=îeX: A single input file is required for a non-link phase when an outputfile is specified
2>Linking…
2>LINK : fatal error LNK1104: cannot open file ‘cudart.lib’
2>Build log was saved at “file://c:\Documents and Settings\jkane\My Documents\Visual Studio 2005\Projects\DynamicCudaLibrary\MyExecRefsDll\Debug\BuildLog.htm”
2>MyExecRefsDll - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 2 failed, 0 up-to-date, 0 skipped ==========
‘cudart.lib’, this is referenced in additional dependences as the path, and in the linker as input.
so maybe someone has an idea.
regards
Jeff