Problem compiling project

Hi, I’m trying to compile a project I’m working on, it has both .cu and .c files.
When I was using only .cu files, there was no problem, but when I’ve started adding .c files, I simply cannot compile.
Here’s the output of nsight compile line:

**** Build of configuration Debug for project cuSimpleDCT ****

make all 
Building file: ../src/
Invoking: NVCC Compiler
nvcc -G -g -O0 -gencode arch=compute_20,code=sm_20 -odir "src" -M -o "src/ca.d" "../src/"
nvcc --compile -G -O0 -g -gencode arch=compute_20,code=compute_20 -gencode arch=compute_20,code=sm_20  -x cu -o  "src/ca.o" "../src/"
Finished building: ../src/
Building file: ../src/ga.c
Invoking: NVCC Compiler
nvcc -G -g -O0 -gencode arch=compute_20,code=sm_20 -odir "src" -M -o "src/ga.d" "../src/ga.c"
nvcc -G -g -O0 --compile  -x c -o  "src/ga.o" "../src/ga.c"
In file included from ../src/ga.h:20,
                 from ../src/ga.c:17:
../src/ca.h:59: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
../src/ca.h:68: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
../src/ca.h:75: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
../src/ca.h:83: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
make: *** [src/ga.o] Error 1

**** Build Finished ****

Can anyone help me out?


And there is no problem when You simply change the ga.c to, right? Tried doing it this way?

The problem continues, just tried that.
I’ve realised that, if for instance I have these two files

int test(void);
int test(void){
  return 0;

and try to use the function test() in another file, say:

#include "utils.h"
int main(int argc, char *argv[]){
  return 0;

I have similar problems, which shouldn’t happen right?

Have You tried to compile the .c files separately, with diffrent compiler (e.g. GCC)?

Yep, and it worked like a charm…strange thing…

NVCC must have been lacking something. I think it needs all the CUDA includes to even compile the source given, but this I am not sure. NVCC manual can be helpful in such matter :)


So, I think I’ve got it sorta working out, I had some static functions giving me trouble.
However, now I can only compile .cu files, not .c, is this supposed to be like this?


I could build your sample code by nvcc. What is the toolkit version you use? Is it CUDA 5.0 Production?

sjiagc, yes it is.
But I’ve fixed the sample problem, the issue now is with .c and .cu…

The cu file is actually a cpp file. So you need to add extern “C” before C function.

I see…would it be bether to make the code always in C++?
I mean for performance and build issues…

Can you check …/src/ca.h:59? It looks like you have CUDA C-specific construct there (e.g. “device” specifier) or something C+±specific.

Note that Nsight specifically sets code language to C in your case (see “-x c”). It may happen that GCC invoked from the command line without such switch autodetects your code as C++ and hence is able to compile it.