如何添加有新扩展名的文件,使之能当作C/C++源文件而被VC编译处理

本文翻译了microsoft的mvp网站上关于添加VC源文件扩展名的文章。介绍了让Visual Studio把.cc后缀文件当作C++源文件处理的方法,如使用/Tp编译选项、修改注册表等,还指出修改注册表更方便,但不能在同一工程混合C和C++文件,此时需用custom build规则。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天读了microsoft的mvp网站(www.mvps.org)上的一篇关于添加VC源文件扩展名的文章

http://www.mvps.org/vcfaq/ide/1.htm)。顺便就把它摘要翻译下来,放在blog上以备参考

原文如下:

Question: How do I get Visual Studio to recognize .cc files as c++ source files?

如何使得Visual Studio能够把.cc后缀名的文件当作C++源文件来(编译)处理。

Answer:  Use the /Tp option of the compiler to instruct it to assume the file is C++. You can put this in as a custom build rule, or modify some registry settings to add .cc to the list of file extensions recognized as C++. The key to modify is:


可以使用/Tp编译选项指示编译器把.cc文件当作C++源文件来进行处理。可以把/Tp命令添加在工程的"custom build"选项中。或者可以通过修改注册表,把.cc后缀名添加到“可当成是C++源文件来处理的文件”的后缀名列表中。要修改的键如下:


HKEY_CURRENT_USER/Software/Microsoft/DevStudio/X.0/Build System/Components/Platforms/Win32 (x86)/Tools/32-bit C/C++/Input_Spec

and

HKEY_CURRENT_USER/Software/Microsoft/DevStudio/6.0/Build System/Components/Tools/<Component 0x3>/Input_Spec

where X is the DevStudio version (5 or 6). You'll probably want to modify the following key to get automatic source code syntax coloring:

X是Devstudio的版本号(5或者是6)。同时可以通过修改下面的键来使得有新后缀名的文件也能使用语法高亮显示功能。

HKEY_CURRENT_USER/Software/Microsoft/DevStudio/X.0/Text Editor/Tabs/Language Settings/C/C++/FileExtensions


This method is nicer because it will save you a lot of work setting up the custom build rules. However, you still have to add the /TP switch manually to the Project Settings to get the compiler to fully recognize the file as C++. The downside: You won't be able to mix C and C++ files in the project, in which case, the only option is using custom build rules.

修改注册表要比通过设置/Tp命令来得方便,当然也可以使用后者。最后,不能通过修改注册表来在同一工程中混合使用C源文件和C++源文件。唯一的可行方法就是使用custom build规则。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值