cuda programs without nvcc?

If one looks at the CudaReferenceManual.pdf (cuda_2.2), Section 3.1.1, it says:

In order to test the C-API which could be compiled without nvcc, I just wrote a sample C-code as follows: (test.c) and compiled it as:

#include <cuda_runtime_api.h>

int main(int argc, char** argv) {

  int32 deviceCount;

  cudaGetDeviceCount(&deviceCount);

  return 0;

}

Am I missing something here? Why isn’t that I’m able to compile the code without nvcc, as the ref-man says above?

One more thing… I’m working on cygwin v1.7 + cuda v2.2, using gcc v3.4.4

API calls that begin with cuda* use the runtime API, while the driver API has calls beginning with cu*.

But then what does the ref-man mean when it says:
“The C API (cuda_runtime_api.h) is a C-style interface that does not require compiling with nvcc.”
When I look into the cuda_runtime_api.h, it has all the cuda* functions only.

No problems compiling and running your program on mac / linux:

$ g++ -o test test.cc -I/usr/local/cuda/include -L/usr/local/cuda/lib -lcudart

$ ./test

Maybe your problem is the result of cygwin?

I think that on windows the runtime API functions are declared assuming C extensions that don’t work with other than MSVC. You’re getting a link error because g++ on cygwin isn’t using those extensions. The driver API assumes less, so I suppose you’d have to use that on windows if you don’t have visual studio.

The following program compiles and runs fine with mingw32:

#include <stdio.h>

#include <cuda.h>

int main(int argc, char** argv) {

  int deviceCount;

  cuInit(0);

  cuDeviceGetCount(&deviceCount);

  printf("found %d devices\n", deviceCount);

  return 0;

}

with

gcc -o test query.c -Ic:/cuda/include c:/cuda/lib/cuda.lib

but fails in the same way on cygwin, because cygwin doesn’t define _WIN32 and nvidia’s libraries assume declaration with __stdcall. Anyway, your original program has the same link error in mingw32.

Thanks MisterAnderson42 and jasonp!
@jasonp: That sounds reasonable. I just used the MSVC cl.exe compiler to compile my program mentioned at the beginning of this post, and yea…!! It compiles the program neatly :)