MSVS C ++, how to compile an already pre-processed file with the * .i extension?

A related question: How to start the MSVC preprocessor and compiler in two different steps?

I explicitly pre-process a MyFile.cpp (not compiling) to MyFile.i . I want to “compile” this file later (obviously skipping the preprocessing would be nice, but as the related question indicates, it seems that this is not possible with MSVS).

PROBLEM: MyFile.i is an "unrecognized extension", and cl.exe assumes that it is an "object file", which results in "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 cannot find a switch to indicate that it is a "source file" (and not an object file). A related question explicitly used the convention " MyFile_preprocessed.cpp ", but I really would rather stay with the (more universal) convention MyFile.i .

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

+4
source share
1 answer

cl.exe has these two flags

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

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

which allows you to compile files with any extension as c or C ++ files

I tried to compile 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

+5
source

Source: https://habr.com/ru/post/1387754/


All Articles