简体   繁体   English

MSVS C ++,如何使用* .i扩展名编译已经预处理的文件?

[英]MSVS C++, how to compile already-preprocessed file with *.i extension?

Related question here: How can I run the MSVC preprocessor and compiler in two separate steps? 相关问题: 如何在两个单独的步骤中运行MSVC预处理器和编译器?

I explicitly pre-process a MyFile.cpp (not compile) to a MyFile.i . 我明确地将MyFile.cpp (不编译)预处理为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.) 我想稍后“编译”该文件(显式跳过预处理会很好,但正如相关问题所示,听起来这对MSVS来说是不可能的。)

PROBLEM: The MyFile.i is an "unrecognized extension", and cl.exe assumes it is an "object file" resulting in a "no-operation". 问题: MyFile.i是一个“无法识别的扩展名”, cl.exe假定它是一个“目标文件”,导致“无操作”。 (See Microsoft warning: http://msdn.microsoft.com/en-us/library/zfsbakc5(v=VS.90).aspx , this warning is active for MSVS 2005, 2008, 2010). (请参阅Microsoft警告: http//msdn.microsoft.com/en-us/library/zfsbakc5 (v = VS.90) .aspx ,此警告对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. 相关问题明确使用了“ MyFile_preprocessed.cpp ”约定,但我真的更喜欢使用(更通用的) MyFile.i约定。

QUESTION: Is there a flag where I can compile a MyFile.i with MSVS? 问题:是否有一个标志,我可以用MSVS编译MyFile.i

cl.exe has these two flags cl.exe有这两个标志

  • /Tc<source file> compile file as .c /Tc<source file>文件编译为.c

  • /Tp<source file> compile file as .cpp /Tp<source file>文件编译为.cpp

that lets you compile files with arbitrary extension as c or c++ files 这允许您将具有任意扩展名的文件编译为cc ++文件

I tried compiling a main.i with the following contents 我尝试使用以下内容编译main.i

#include <iostream>

using namespace std;

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

with cl /Tp main.i and it works as advertised 使用cl /Tp main.i ,它的工作方式与广告一致

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在另一个 C++ 程序中使用 preprocessed.i 文件? - How to use a preprocessed .i file in another C++ program? 有没有办法用clang有效地编译已经预处理的文件? - Is there a way to efficiently compile already preprocessed file with clang? 如何在 MSVS 中为 Windows XP 编译 C++ 应用程序? - How to compile C++ app for Windows XP in MSVS? C++:在 VSCode 中生成预处理文件 - C++: Generating Preprocessed File in VSCode 如何在 vscode 扩展中检索 C/C++ 文件的编译命令 - How to retrieve compile command for C/C++ file in a vscode extension 如何在Linux中编译后以这样的方式编译c / cpp代码以提供经过预处理的汇编文件和目标文件? - how to compile c/cpp code in such a way that it gives preprocessed assembled and object file after compilation in linux? 如何使用VS编译器将预处理文件编译为目标文件 - How to compile a preprocessed file into object file using VS compiler 预处理的 C/C++ 文件是机器特定的吗? - Is a Preprocessed C/C++ file machine-specific? C ++宏仅在预处理到文件时有效 - C++ macro only works when preprocessed to a file 为什么我会在使用其他库时遇到 LNK4098 冲突 - 尝试在 MSVS2010 Express 中编译 C++ 时? - Why do I get LNK4098 conflicts with use of other libs - when trying to compile C++ in MSVS2010 Express?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM