Thursday, July 26, 2007

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

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:

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


HKEY_CURRENT_USER\Software\Microsoft\DevStudio\6.0\Build System\Components\Tools\\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:

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.

IMPORTANT: This procedure contains information about modifying the registry. Before you modify the registry, make sure to back it up and make sure that you understand how to restore the registry if a problem occurs. For information about how to back up, restore, and edit the registry, click the following article numbers to view the Microsoft Knowledge Base articles:

256986 - Description of the Microsoft Windows Registry

322756 - HOW TO: Back Up, Edit, and Restore the Registry in Windows XP.

No comments: