How to instruct cuda to use c compiler not c++ one

I am converting a numerical model written in c to support cuda. There are c some features that do not link with c++ linker. For example, by just changing the .c to .cpp postfix for all c files (not any cuda functions yet), the compilation went through but link failed due to some unresolved symbols.

So I am wondering whether there is a specific file postfix other than .cu that can instruct cuda to use c compiler/linker explicitly. Thanks


not a postfix, but individual function declarations and definitions can be tagged as extern “C” to resolve your linking issues. It disables the C++ specific name mangling of functions, so that other C code can link to it.

alternatively extern “C” can also apply to an entire block of code using curly brackets

extern “C”
// some function definitions/declarations here

Thanks! Could you take a look at my files and see why they do not even compile? This example is a very simplified version that can duplicate my problem. It is not allowed to add attachment so I put my example in code blocks blow.

#include "func.h"
#include <stdio.h>
int main()
	double v = 1.0;
	printf("%f converted value is %f", v, convert(v, 2));
    return 0;

const double Var[6] = { 1.0,     448.831, 0.64632,
						0.02832, 28.317,  2.4466 };

#include "func.h"

extern double Var[];  // var defined in file1.cpp

double convert(double v, int i)
	return Var[i] * v;


#pragma once
double convert(double, int);