Question

Related question here: How can I run the MSVC preprocessor and compiler in two separate steps?

I explicitly pre-process a MyFile.cpp (not compile) to a MyFile.i. I want to later "compile" that file (explicitly skipping preprocessing would be nice, but as the related question suggests, it sounds like that is not possible with MSVS.)

PROBLEM: The MyFile.i is an "unrecognized extension", and cl.exe assumes it is an "object file" resulting in a "no-operation". (See Microsoft warning: http://msdn.microsoft.com/en-us/library/zfsbakc5(v=VS.90).aspx, this warning is active for MSVS 2005, 2008, 2010).

I can't find a switch to state that it is a "source file" (not an object file). The related question explicitly used the "MyFile_preprocessed.cpp" convention, but I'd really rather stay with the (more-universal) MyFile.i convention.

QUESTION: Is there a flag where I can compile a MyFile.i with MSVS?

Was it helpful?

Solution

cl.exe has these two flags

  • /Tc<source file> compile file as .c

  • /Tp<source file> compile file as .cpp

that lets you compile files with arbitrary extension as c or c++ files

I tried compiling a main.i with the following contents

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world \n";
    return 0;
}

with cl /Tp main.i and it works as advertised

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top