Compiler complaining about correct C code

I am porting an existing C application to run partly on a GPU. The original code compiles without complaint when using gcc, but when using nvcc on the new version, it complains about things in some of the C files that I haven’t altered, and I can’t see why it is complaining.

The errors that I get are:

…/mpi_s/mpi.h(119): error: expected a “)”

…/mpi_s/mpi.h(121): error: expected a “)”

io_harness.h(23): error: identifier “FILE” is undefined

io_harness.h(24): error: identifier “FILE” is undefined

io_harness.h(29): error: identifier “FILE” is undefined

io_harness.h(30): error: identifier “FILE” is undefined

io_harness.h(31): error: identifier “FILE” is undefined

io_harness.h(32): error: identifier “FILE” is undefined

gpu.cu(129): error: expected a “)”

line 119 of mpi.h is:
int MPI_Type_contiguous(int count, MPI_Datatype old, MPI_Datatype * new);

line 121 of mpi.h is the second line below (a continuation of a declaration started on line 120):
int MPI_Type_vector(int count, int blocklength, int stride, MPI_Datatype old,
MPI_Datatype * new);

I can’t see what is wrong with either of those, and there are many other lines around them that are very similar which it doesn’t complain about.

stdio.h is included in io_harness.h, so I can’t understand why ‘FILE’ is undefined.

Note that I did not alter mpi.h or io_harness.h from the original which compiled with gcc.

I did create gpu.cu, and line 129 is:
cudaMemcpyToSymbol(siteforce_d, &siteforce, sizeof(double*3), 0, cudaMemcpyHostToDevice);

Again there are many almost identical lines surrounding this which it doesn’t complain about.

If I compile the original code (no CUDA) with nvcc it doesn’t complain. If I rename one of the files from .c to .cu, but make no other changes (other than creating a new rule in the Makefile for compiling .cu files, which is the same as the rule for compiling .c as I am using nvcc for both), then it gives the same complaints about the mpi.h, but it didn’t complain about io_harness.h.

I am using CUDA 2.1 beta on RHEL. Any ideas about this would be appreciated.

And I have now tried it with CUDA v2.2 and it produces the same errors. If you want to see more of the code, I can post it.

nvcc compiles .cu files as though they were C++, not C. you can try the --host-compilation=C keyword, but it still probably won’t work because it still uses a C++ front-end (just with the vast majority of C++ features disabled).

Thanks for the reply.

Yes, I had tried doing that already. As you predicted, it still produces the same errors. Is there any way around it? It seems strange that it complains about some lines while it says nothing about others surrounding them that are almost identical.