Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C vs C++ using cl compiler in VS2015

How does the cl compiler know whether I'm compiling C or C++ code?
Do I need to tell the compiler?
I am running out of the Developer Command Prompt for VS2015. I originally started this project with c++ code that compiled and ran on a RedHat Linux PC. I moved it to WIN7 and it would not compile under the cl compiler unless I got rid of the c++ constructs and implemented C equivalents.
A constructor in a header file was one of the issues I had to work around.

like image 818
E Purdy Avatar asked Aug 31 '25 18:08

E Purdy


1 Answers

As documented in MSDN, it first looks at the filename extension. If it is .cpp or .cxx then it defaults to C++ compilation. Almost always good enough to get the job done. That same page also shows how to force the selection, use /Tc for C and /Tp for C++. You'd use /TC and /TP to force it for all source files.

like image 170
Hans Passant Avatar answered Sep 02 '25 07:09

Hans Passant