Cross compiling in Vista 64 with CUDA 64, almost got it :(

Hello guys, I’ve been wanting to try CUDA for a while but never got do it. Now that I’m finally here I’ve been trying to get the cross compiling to work but I always met barricades which stopped me from advancing. I work in VISUAL STUDIO 2008 btw.

Alright here is the steps I’ve been doing it:

1: Install Driver (190.xx), 64 bit toolkit and 64bit SDK.

2: I opened up the sample projects from the SDK and compiled succesfully the first try in x64 mode.

3: Now time for 32 bit compiling. I choose win32 and compile. I get errors immidiately.
What I did at this step is to read on the forums about what was causing it. I did those steps below to fix it:
step 1: add --machine 32 to extras in properties at the CUDA Build RUle 2.3.0
step 2: I Right click on my computer, got to systemsettings and enviroment variables. I added my own version of them such as CUDA_LIB_PATH32 and CUDA_BIN_PATH32 and kept the regular ones which were pointing to the 64 bit folders. My ones now point to 32 bit folders. I saw this suggested somewhere but I didn’t know how this would help me though.
Step 3: I changed the path in the linker so it points to CUDA_LIB_PATH32 instead of CUDA_LIB_PATH. Hence, 32 bit version.

4: Now I tried building it and it told me missing cutil32d.lib. Time to research on the forums again and then people said that I had to rebuild the cutil solution inside the nvidia folder in win32 debug mode. I did it and tadaa, got the lib files in 32bit.

5: Now I build in 32bit again and it compiles and run, but exists with “can’t find cudart.dll”. It also shows in visual studio this error code: 0xc000007b

Now as you guys see I normally research about the errors before posting. I found a thread about this error message at page 2 where people say declare enviroment variables ( which I did already in step 3 part 2 ). But I can’t get it to find the right cudart.dll file. If I copy the 32 bit one from C:\Cuda\bin to the project folder, it all works. But I want it to work without doing that, and I saw some people in the forums that got it to work with those enviroment path variables, but I have no ideas how to use my path variable so it detects the correct dll, in this case the path is declared as CUDA_BIN_PATH32.

I saw in the documentation that cross compiling is possible with version CUDA 2.3 but oh boy I never thought it would take this much time to actually get it to work V_V"

If someone could help me out to get this fixed so it finds the correct DLL, you would have my thanks.

Regards Enduriel!

what’s your environement variable “Path”? It should contains C:/CUDA/bin64

If you mean the one under mycomputer --> properties --> advanced system settings --> enviroment variables, then yes CUDA_BIN_PATH points to C:\CUDA\bin64, I added my own one as I said in the main post which I named CUDA_BIN_PATH32 which points to C:\CUDA\bin, but I don’t know how to use these in visual studio 2008. I tried them in several fields in the properties window and it always gave the same error, that the cudart.dll is missing. I made the regular env path point to C:\CUDA\bin instead of 64 under advanced system settings --> env vars but then it gives error because C:\CUDA\bin folder don’t contain the nvcc.exe.

OS would load cudart.dll (when linking with cudart.lib) from

(1) local directory (your current project)

(2) from directory in PATH variable

remark: I don’t think that OS would find cudart.dll in direcotry defined by CUDA_BIN_PATH

you can copy C:\CUDA\bin\cudart.dll into your project directory or

add C:\CUDA\bin to your PATH variable.

Yeah I know it works by copying it to the project directory. But I want it to work without doing that. May I ask which path variable you are talking about and HOW you add it so it searches in that folder in visual studio??
I want it to compile to 32 bit with 64 bit version and only way is with copying that .dll to project folder right now.

I think that you have added C:\CUDA\bin to enviroment variable “Path”, and nvcc.exe is not in C:\CUDA\bin,

so you have error message.

if you add both C:\CUDA\bin and C:\CUDA\bin64 in C:\CUDA\bin “Path” and C:\CUDA\bin64 is in front of C:\CUDA\bin,

then nvcc.exe is found but cudart.dll in C:\CUDA\bin64 is also loaded when application is running.

I search related articles via google and there is an article in MSDN library that may solve your problem. Please see

accroding to description in the article, you can try

[codebox]#include <Windows.h>

char *str1 = "C:\\CUDA\\bin\\cudart.dll" ;


LoadLibrary( str2 );[/codebox]

this would load C:\CUDA\bin\cudart.dll directly without searching for environment variable “Path”

Tried that code and got same error message that it finds wrong version of cudart.dll :( (0xc000007b). Where do I put the enviroment variable in visual studio btw?

This is how my path variables look like right now but I don’t know how to add it to VISUAL STUDIO so it searches there, is it somewhere in properties or somewhere else :(?

sorry, OS still load DLL when application starts vis Dllmain function, so I search related articles from google,

I found a useful link about “Linker Support for Delay-Loaded DLLs”

experiment: suppose I just use cuda runtime library (no cublas and cufft), then

in project setting

property --> linker --> input --> Delay Loaded DLLs: cudart.dll

in main function

[codebox]#include <Windows.h>

int main(int argc, char*argv )


LPCTSTR str2 = L"C:\\CUDA\\bin\\cudart.dll" ;

if ( NULL == LoadLibrary( str2 ) ){

	printf("loading cudart.dll fails\n" );

	wprintf(L"Format message failed with 0x%x\n", GetLastError());


	printf("loading cudart.dll succeeds\n" );


// your code


now OS does not load cudart.dll when program starts but load expicitly by helper function LoadLibrary()

That didn’t work either =/ I’m pretty sure there is just a small mistake somewhere in my configuration that doesn’t let me do 32bit compiling.
If you check this thread:…st=#entry570060
Same thread another guy who got it to work:…rt=#entry574073

What does HE mean with:
3) Add %CUDA_BIN_PATH32% and %CUDA_BIN_PATH64% to the PATH. The order doesn’t seem to matter, but I have the 64-bit one first.

WHERE do I add %pathvariables% in visual studio? I think this is where I fail :(

just add C:\CUDA\bin64 and C:\CUDA\bin into environment variable “PATH” in control panel --> system. (not in visual studio)

you have added CUDA_BIN_PATH as environment variable but this is not in the search order of dll.

I add C:\CUDA\bin64 and C:\CUDA\bin into environment variable “PATH” and it does work.

if it still does not work, please post your environment variable “PATH”. Just type command “set” in command Prompt and

search for “PATH”.

Haven’t I done that already here in this image? Or am I missing something? Or is there a way to put 2x path in same variable?…st&id=13558

It also shows up on the command prompt when I type set. This is damn frustrating >.<

I add C:\CUDA\bin64 and C:\CUDA\bin into environment variable “PATH” as figure 1

figure 1

if it still does not work, please check your environment variable “PATH”. Just type command “set” in command Prompt and

search for “PATH” as in figure 2. You should see C:\CUDA\bin64 and C:\CUDA\bin (in red rectangle)

figure 2

OMG LOL! SO THIS WAS MY PROBLEM ALL THE TIME -_-!!! IT WORKS MAN THANKS ALOT <3! Damn I feel completely useless haha. Thanks again m8, I’m in your debt seriously!

If you ever need something in terms of 3D Models just leave me a note I’ll try to pay my debt in that way. I’m a student in Futuregames Academy (3D ART) though I started with 3D when I was around 12. Some work of mine :)

as I said, if you ever need something in 3D, I’ll try to help you :)

Piece out m8 and thanks again :)