Starting cuda development: linking problem

Hi everyone,
I’m starting developing with CUDA. To learn I want to “translate” a program written in C. The first thing I tried was to simply change the extension from *.c to .cu of the file containing the main(). But here come the problems. If I compile every file (.c and *.cu) with nvcc it works like a charm but if i try to compile the *.c files with gcc and the *.cu file with nvcc and link the stuff together (with gcc) the program starts to give absurd results (but it compiles and links!). It would be nice to be able to separate compiling steps (I use a makefile) rather than using only nvcc. I use ubuntu and I tried with gcc4.3 and gcc4.2. I wanted to know if this is a known problem, or maybe I have to use some exotic flag to make this stuff work.
I’m programming in C so I usually use the --host-compilation c flag.

thanks for the help and have a nice weekend everyone

You can just use nvcc -c to compile CUDA source to objects and link them with gcc (unless you want to do source debugging, then you need to use nvcc to link). At worst all you need to provide is the CUDA libraries you are using (libcuda or libcudart depending on the API you are using).

Thank you very much for your reply.

That’s what I’m trying to do atm. I compile to objects with -c both *.c (with gcc) and *.cu (with nvcc). But when I link objects together I end up with a “wrong” program, in the sense that it doesn’t work well (its output is clearly wrong). I wanted to know what’s the difference between compiling+linking with nvcc and compiling *.cu with nvcc, *.c with gcc and linking them together with gcc. From what I understand reading the docs, there shouldn’t be any difference at all, or i’m doing something wrong?

There is no difference. Linking either works or fails, there is no intermediate state. If your results are wrong, the build process is the last thing I would be worrying about.