cuda vs2005 dll functions cannot open file 'cudart.lib'

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

//CudaFuncsDll.cpp

#include “CudaFuncsDll.h”

#include

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

hello,

Did you link libraries?
Project properties > links editor > general
Libraries directory input : “$(CUDA_LIB_PATH)”

and

Project properties > links editor > input
cudart.lib

Yes, well, actuallyi went back and checked them, i did not use the $ parm, just hardcoded it, anyway, all additional dependences now say

$(CUDA_LIB_PATH); C:\Documents and Settings\jkane\My Documents\Visual Studio 2005\Projects\DynamicCudaLibrary\CudaFuncsDll

the first one is for cuda, the second one is for the h file.

this parm is code in 6 places,

Cudafuncsdll

linker

c/c++

cuda

Myexecrefsdll

linker

c/c++

cuda

and the linker in both / input reference cudart.lib (cuda runtime library)

if i do a clean, then complete rebuild i get:

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:\CUDA\lib" -I"C:\Documents and Settings\jkane\My Documents\Visual Studio 2005\Projects\DynamicCudaLibrary\CudaFuncsDll" -I"CC:\CUDA\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\CudaFuncsDll.cu.obj” “c:\Documents and Settings\jkane\My Documents\Visual Studio 2005\Projects\DynamicCudaLibrary\CudaFuncsDll\CudaFuncsDll.cu”

1>CudaFuncsDll.cu

1>tmpxft_00000a7c_00000000-6_CudaFuncsDll.compute_10.cudafe1.gpu

1>tmpxft_00000a7c_00000000-10_CudaFuncsDll.compute_10.cudafe2.gpu

1>CudaFuncsDll.cu

1>tmpxft_00000a7c_00000000-3_CudaFuncsDll.compute_20.cudafe1.gpu

1>tmpxft_00000a7c_00000000-14_CudaFuncsDll.compute_20.cudafe2.gpu

1>CudaFuncsDll.cu

1>tmpxft_00000a7c_00000000-6_CudaFuncsDll.compute_10.cudafe1.cpp

1>tmpxft_00000a7c_00000000-20_CudaFuncsDll.compute_10.ii

1>Compiling…

1>stdafx.cpp

1>Compiling manifest to resources…

1>Linking…

1>LINK : C:\Documents and Settings\jkane\My Documents\Visual Studio 2005\Projects\DynamicCudaLibrary\Debug\CudaFuncsDll.dll not found or not built by the last incremental link; performing full link

1>LINK : warning LNK4098: defaultlib ‘MSVCRTD’ conflicts with use of other libs; use /NODEFAULTLIB:library

1>Embedding manifest…

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), 1 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\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\MyExecRefsDll.cu.obj” “c:\Documents and Settings\jkane\My Documents\Visual Studio 2005\Projects\DynamicCudaLibrary\MyExecRefsDll\MyExecRefsDll.cu”

2>MyExecRefsDll.cu

2>tmpxft_00000ef8_00000000-6_MyExecRefsDll.compute_10.cudafe1.gpu

2>tmpxft_00000ef8_00000000-10_MyExecRefsDll.compute_10.cudafe2.gpu

2>MyExecRefsDll.cu

2>tmpxft_00000ef8_00000000-3_MyExecRefsDll.compute_20.cudafe1.gpu

2>tmpxft_00000ef8_00000000-14_MyExecRefsDll.compute_20.cudafe2.gpu

2>MyExecRefsDll.cu

2>tmpxft_00000ef8_00000000-6_MyExecRefsDll.compute_10.cudafe1.cpp

2>tmpxft_00000ef8_00000000-20_MyExecRefsDll.compute_10.ii

2>Compiling…

2>stdafx.cpp

2>Compiling manifest to resources…

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: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

i know it seems obvious, i don;t have the lib in the path, but i’m runing out of places to include a dependency

regards

Jeff :shifty:

Hello all,

well, after doing things over, i now get it to work,

the problem occurs if you have “configuration type” = dll

if you change it to anything else, for example lib, (a static link lib), all is well,

so for now i will use a lib rather than a dll

maybe someone has some ideas why it fails only on creating a dll

regards

Jeff

Are you working with 32 or 64bits? Because sometimes libraries names change like “cudart32.lib” or “cudart64.lib” (examples)

just 32 bits, the lib actually exists and seems to be in the correct place, to get it to fail, i just have to change from lib to dll, then it fails, i would prefer to use a dll rather than a lib but for now it works with lib (static functions), i also probably should tell you i have 1 solutions and two projects, one is used to make the dll (which consists of a h file and a cu file) and the other is used to make the application (which only includes the h file and then uses the function. the functions library is just used so i can make functions without affecting the application. when a new function is created i simply have to inform the development groug that they can use a new function.

regards

Jeff