When I select console project to start with, it lets you to select C or C++. But once its created, I can't figure out how to change it. Plus, when you create a Win32 GUI application, it doesn't give you the option at all and its default is C++.
Where can I change to C? I have been looking in all the project settings for ages. Renaming my file from .cpp
to .c
doesn't seem to do anything, it compiles the file as C++. I know that without the IDE, you just change your executable from g++
to gcc
, but how do I set this for the current project in CodeBlocks?
The only tangible difference between selecting C vs C++ when you create a project is which compiler is invoked for the translation units during a build. Code::Blocks currently does not provide a way to directly change this after project creation. That is to say you would have to change each source file one at a time to get what you want.
Here's what you can do to change it:
Now if your existing project contains a lot of source files you can do this quicker by manually editing the Code::Blocks .cbp
project file (it's just an XML file). The nodes you want to search for and replace will look something like this:
<CodeBlocks_project_file>
<!-- ... -->
<Project>
<!-- ... -->
<Unit filename="source1.cpp">
<Option compilerVar="CPP" /> <!-- Change CPP to CC here -->
</Unit>
<Unit filename="source2.cpp">
<Option compilerVar="CPP" /> <!-- And here -->
</Unit>
<Unit filename="source3.cpp">
<Option compilerVar="CPP" /> <!-- And here then save. -->
</Unit>
<!-- ... -->
</Project>
</CodeBlocks_project_file>
After the changes, open your project in Code::Blocks and confirm it's being compiled as a C source file. You should see the build log invoking gcc
now instead of g++
.