简体   繁体   English

使用文件本身的指令强制文件编译为 C

[英]Force file to be compiled as C, using a directive from the file itself

I have some old code files in my C++ project, that need to be compiled as C code - the entire codebase is set to compile as C++.我的 C++ 项目中有一些旧代码文件,需要编译为 C 代码 - 整个代码库设置为编译为 C++。 I am using Visual Studio, but I'd rather avoid setting this per-file from the project properties, and would rather use some kind of #pragma directive (if possible).我正在使用 Visual Studio,但我宁愿避免从项目属性中设置这个每个文件,而是宁愿使用某种#pragma指令(如果可能的话)。

I have searched around, but found nothing, the closes I could think of is to add an #ifdef , that checks for __cplusplus and fails if does so.我四处搜索,但一无所获,我能想到的关闭方法是添加一个#ifdef ,它检查__cplusplus并在这样做时失败。

Basically I am looking for a way to inject the /Tc, /Tp, /TC, /TP (Specify Source File Type) commands from the source.基本上,我正在寻找一种从源代码注入/Tc、/Tp、/TC、/TP(指定源文件类型)命令的方法。

"By default, CL assumes that files with the.c extension are C source files and files with the.cpp or the.cxx extension are C++ source files." “默认情况下,CL 假定扩展名为 .c 的文件是 C 源文件,扩展名为 .cpp 或 .cxx 的文件是 ZF6F87C9FDCF8B3C3F07ZF93F1EE8712C9 源文件。”

So rename the files if nessesary and put the new c files to your projekt.因此,如果需要,请重命名文件并将新的 c 文件放入您的项目中。

If neded set the compiler options: Set compiler如果需要设置编译器选项: 设置编译器

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM